Be more productive with shell aliases

Dane Hillard on January 26, 2019

The most valuable time as a software developer is usually time spent collaborating and thinking. To get as much of that time as possible, reduce ... [Read Full]
markdown guide
 

You could actually shorten your pull and push git commands a bit. Oh My Zsh also has ggl which is an alias for git pull origin $(current_branch). The plugin keeps track of which branch you are on in the current_branch variable. When you are on the master branch the alias would end up being git pull origin master, if you were on a branch named feature it would be git pull origin feature. The same rules apply to the ggp alias, defined as git push origin $(current_branch).

 

That's how ggpush and ggpull work too, but I didn't know about the shorter-named functions! Guess I really need to read through all the functions in that plugin, heh. Thanks!

 

Thanks Man, really like your aliases. Mainly goop (will use now).

One mine that i really like is:

alias new-feature="git reset --hard HEAD && git checkout master && git pull origin master && git checkout -b $@"

I throw actual changes (if need i stash), go to master get all changes from my teammates and create a new branch with actual changes.

This improve a lot my workflow.

 

Nice! My upr is sort of similar, but favors stashing existing changes and doesn't create a new branch. Maybe I can combo that with another to include the branch creation part, because that's usually what I do next! Thanks for sharing 🤗

 

This is a neat read! I started writing some of my own aliases, but now using EMACS, I'm trying to find a good Git mode that does what I need.

I've tried to use normal words so that chaining aliases is more like speaking a sentence. There are obviously limitations to this; My traversal aliases are go /path/to/file.txt (cd) or m to ../other/directory/ file.txt (mv -vn, -t). For Git my status command is working, or working ofstaged (--cached), or working ofuntracked (--no-index).

Lately I had struggled with finding ways to name my stash commands, I came up with stash (save), stashes (list), unstash (apply), destash (pop).

 

Nice, I like the expressivity! named is definitely one my favorite aliases for that reason. I would love a clean way to have commands like move {path} to {other path} or compare {branch} to {branch} without writing functions that do too much heavy parsing...at the same time, I do like the brevity of the commands. In my head they still say "git create branch" or "git checkout" rather than "gee-cee-bee" or "gee-cee-oh" 😄

 

Make a lot of sense this, i follow it in my alfred commands, will use too. Thanks

 

My handy aliases for *nix commands:
alias lt='ls -lt'
alias ltr='ls -ltr'
alias ltm='ls -lt|more'
alias ltrm='ls -ltr|more'
alias latr='ls -latr'
alias ltr8='ls -ltr|tail -8'
alias ltr22='ls -ltr|tail -22'
alias ltd='ls -lt|grep "d"'
alias ltdm='ls -lt|grep "d"|more'
alias findx='find . -print'
alias findxm='find . -print|more'
alias findxwc='find . -print|wc'

 

Always nice to see ways to make things easier. I usually use the gui in jetbrains ides, but I think it is very important to first know what the gui is doing under the hood, and second have good ways to be productive without a full blown ide.

 

Such a great point. Productivity is an abstraction layer on top of things you understand well! Otherwise when something bad happens you won't know how to correct it.

 

With the Git plugin aliases, this workflow takes a lot less work:

To me, that looks like about 15-20% fewer letters to type to do essentially the same commands as before. It has none of the benefits of a script to make the process idempotent, won't work on someone else's computer and looks inscrutable in your shell history.

Looking over your shoulder or pair-programming? I have no idea what gstp does, because it's not something that exists outside of your alias list and I can't easily infer from context. It does something to do with git, but that's as far as I get before I have to add the next line to my cognitive load.

I know why you want to use aliases, and I know they're handy. From mine:

# ahem.
alias gti=git
 

To each their own, of course! I also use scripts liberally, and make a point to fully type out my commands if I happen to be working with someone else 😊

 

PS: the ltd and ltdm aliases didn't display a caret: grep "d"

code of conduct - report abuse