1

What are the most useful aliases in your bashrc or zshrc

 2 years ago
source link: https://lobste.rs/s/qgqssl/what_are_most_useful_aliases_your_bashrc
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What are the most useful aliases in your bashrc or zshrc

What are the most useful aliases or functions etc for bash that you’ve collected or written? Or bash scripts. Please give explanation/usage if necessary. Ones you actually use often. Thanks!

igemnace

edited 1 hour ago

| link

Oh, I have quite a few!

For shell aliases and functions:

vg: Shell function to open grep results directly in Vim using the quickfix. A bit of expounding here, in a small blog post.

  • rg foo (with ripgrep) to simply view results
  • vg foo to use the results as a jumping point for editing/exploring in Vim.

A ton of aliases to shorten frequently used commands. Few examples:

  • When I want to sync a Git repo, I run gf to fetch, glf to review the fetched commits, then gm to merge. git pull if I’m lazy and want to automatically merge without reviewing
  • glp to review new local commits before pushing with gp. Both glf (“git log for fetch”) and glp (“git log for push”) are convenient because my shell prompt shows me when I’m ahead or behind a remote branch: https://files.emnace.org/Photos/git-prompt.png
  • tl to list tmux sessions, then ta session to attach to one. I name tmux sessions with different first letters if I can help it, so instead of doing ta org or ta config, I can be as short as ta o and ta c

Also, “aliases” for Git operations that I relegate to Fugitive. Technically these are shell functions, but they exist mostly just to shorten frequently used commands.

  • Instead of gs for git status, I do vs and open the interactive status screen from Fugitive (which after a recent-ish update a few years ago, is very Magit-like, if you’re more familiar).
  • When I’m faced with a merge conflict, I do vm to immediately open Vim targeting all the merge conflicts. The quickfix is populated, and I jump across conflicts with [n and ]n thanks to a reduced version of vim-unimpaired.

For scripts:

First off, an easy way to manage my PATH scripts: binify my scripts so they go into PATH, binedit if I need to make a quick edit.

ez: Probably my favorite one. A script to run FZF, fuzzy-find file names, and open my editor for those files. Robust against whitespaces and other special characters. I also have a short blog post expounding on it.

watchrun: A convenience command to watch paths with inotifywait and run a command for each changed file. For example, watchrun src -- ctags -a to incrementally update a tags file.

notify-exit: Run a command and shoot off a libnotify notification if it finishes (whether with a successful exit code or not). I have it aliased to n for brevity (using a symlink). For example, n yarn build to kick off a long-running build and be notified when it’s done.

  • Also, a remote counterpart rnotify-exit, which I have aliased to rn (using a symlink). For example, rn ian@hostname yarn build on a remote machine (within my LAN) to kick off a build, and have it still notify on my laptop.

And a slew of scripts that are a bit more integrated with tools I use, e.g.:

I normally keep these in fixed locations, so everything I’ve accrued naturally over the years should be here:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK