# Fast shortcuts
alias c='clear'
alias r='reset'
alias q='exit'
alias cd..="cd .." # I often make this mistake
# Because sometimes you don't have the time to put this two letters
alias ..='cd ..'
alias ...='cd ../..'
alias -- -="cd -"
# Doing a fast proxy, good for watching netflix and youtube without restrictions
alias proxy='ssh -C2qTnN -D 8080'
# To search process with more details
alias pp="ps axuf | pager"
# Because I forget the name :(
alias explore="ranger"
# Because NeoVim is awesome :)
alias vim=nvim
# Do something and receive a desktop alert when it completes `sudo apt-get install something | alert`
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Search process by name and highlight !
function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; }
# Search for files and page it
function search() { find . -iname "*$@*" | less; }
The incredible amount of time this has saved over the years is great, but the real benefit never having remember either inspect archive files for the initial directory or remember to do this dance:
% mkdir foo
% cd foo
% tar zxvf /path/to/bar.tar.gz # or "unzip foo.zip" or "7x x foo.7z" etc
% mv bar-1.2.3 ..
% cd ..
% rmdir foo
I used to use something similar, but atool is far superior. It handles quite a few situations, but the most important is that it will decompress into the current directory (as a normal "tar zxvf foo.tar.gz" or "unzip foo.zip") if-and-only-if there was exactly one file or directory at the top level of the in the archive. If the archive was packaged badly, it will leave the resulting files in the temporary directory it creates. Also, atool leave the file(s) in the temporary directory in the event of a name collision, so you protected from the risk of clobbering existing files.
Without atool you have to either 1) create a temporary dir youself and do the dance I showed above, or 2) always inspect every archive before you decompress it to see if it has multiple top-level files, or 3) accept that typing "tar xvf" or similar will sometimes spam your current directory (often $HOME) with thousands of files.
Similar to how git tends to remove mental blocks around branching (you not longer have ot worry about the cost of making an arbitrary change), atool frees you from having to worry about how an archive was created. This has, in practice, saved huge amount of time and mental effort.
Here are a few I haven't seen in a lot of places but come in really handy.
First, alias this on Linux to get the 'open' command to work like OSX (e.g. 'open file.pdf'). It shadows a real 'open' command, but I have never used it, so no big loss :
alias open='xdg-open'
The second one I use all the time. A process that is stuck on I/O (or other uninterruptible syscalls), or even a Python interpreter stuck in a C extension, won't always respond well to Ctrl-C. However, Ctrl-Z (suspend) and this alias (kills the last suspended process group) do work relatively well :
alias killit='kill -9 %%'
This one I use a lot for copying the output of a command to the clipboard. Just run 'command | pbcopy' and then Ctrl-V elsewhere. pbcopy is actually an OSX command, I aliased it on Linux for ease of use :
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
This one runs a program under GDB. You can run e.g. 'gdbrun =python test.py' and debug C extensions more easily:
I use most of the oh-my-zsh builtins. The git ones save a ton of time and G='|grep' is brilliant.
alias GD='git diff HEAD~1 HEAD'
alias grv='git review'
alias gunmod='git status | grep "modified" | awk "{print \$2}" | xargs -I{} git checkout -- {}'
alias gv='gvim --remote-silent'
alias json='| python -m json.tool'
alias vg='vagrant'
alias ans='ansible '
alias ansp='ansible-playbook '
alias vv='virtualenv venv'
alias vvp='venv/bin/python'
alias vvpi='venv/bin/python setup.py develop'
alias yt='cd $HOME/downloads; youtube-dl --verbose'
alias yt3='cd $HOME/downloads; youtube-dl --verbose --extract-audio --audio-format mp3 '
I keep all of my shell history, right now it think it goes back ~3 years, so every now and then I filter it by frequency and check if I am using a command often enough to justify an alias. Works quite well
Is the beginning pipe intended? If I just run 'python -m json.tool' then it starts reading from stdin by itself (and works as intended). And with the pipe, I can’t seem to make the alias work.
# git branch ahead/behind another
function gahead() {
# use first argument or master
original=${1-master}
# use the second argument or current branch if not given
current=`git branch | grep \* | sed s/\*\ //`
compare=${2-$current}
# run git rev-list and capture numbers returned
result=`git rev-list --left-right --count $original...$compare`
# print numbers in a pretty message
numbers=($result);
echo -e "$Red-$Color_Off $compare is currently $IRed${numbers[0]}$Color_Off commits behind $original";
echo -e "$Green+$Color_Off $compare is currently $IGreen${numbers[1]}$Color_Off commits ahead of $original";
}
Edit: if it's not clear you would use this like:
$ gahead #checks current branch against master
$ gahead development #checks current branch against development
$ gahead development foo #checks foo branch against development
NB: this is checking local branches, not remote branches.
Starting a (generally GUI) application in the background and detaching it as much as possible from the current terminal, so it doesn't quit on a SIGHUP. I have this as a bash script (~/bin/bgrun), but it could pretty easily become an alias or function:
I have the same script, calling it nnohup in my ~/bin folder.
Common GUI programs I often launch from the command line I put an alias in my .bashrc for. e.g.
alias thg="~/bin/nnohup /usr/bin/thg"
alias rabbitvcs="~/bin/nnohup /usr/bin/rabbitvcs"
alias meld="~/bin/nnohup /usr/bin/meld"
alias xnview="~/bin/nnohup /usr/bin/xnview"
alias dolphin="~/bin/nnohup /usr/bin/dolphin"
alias vlc="~/bin/nnohup /usr/bin/vlc"
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
# search history (??) and processes (???)
alias '?=fc -li 1'
alias '??=fc -li 1 | grep '
alias '???=ps-grep'
alias m='less'
alias su='sudo -H -s'
# move to trash rather than deleting
rm='trash-put -v'
# simplify hard to remember command names
alias pk-show='apt-cache show'
alias pk-install='sudo apt-get install'
alias pk-update='sudo apt-get update'
alias pk-update-upgrade='sudo apt-get update && sudo apt-get upgrade'
alias pk-uu=pk-update-upgrade
alias pk-remove='sudo apt-get remove'
alias pk-debinst='sudo dpkg -i'
pk-search () {
apt-cache search $1 | sort | egrep "${1}|$"
}
Use magit in emacs as a git front-end instead of dozens of git aliases. You can continue to use vi or eclipse or whatever for editing. Use dired in emacs to replace a lot of file manipulation aliases.
Replace all your complicated aliases with ^r reverse search. For example, instead of typing
sudo dnf --refresh check-update
I type
^rche
because 'check' is the most distinct string in that command in my mind, and by 'che' bash has already located the last time I typed it in the history. Save lots of history:
HISTSIZE=100000 # Lots of history.
HISTFILESIZE=100000 # Lots of history in the file.
HISTCONTROL=ignoreboth # Ignore entries with leading white space and dupes.
HISTIGNORE="ls:ll:cd:fg:j:jobs" # Uninteresting commands to not record in history.
shopt -s histappend # Append history to file, don't overwrite.
shopt -s histverify # Show expanded history before running it.
shopt -s cmdhist # Store multiline cmds as single
I made a bash function for easier alias binding. It makes aliases immediately available and permanent. Also you don't need quotes so you can use tab completion etc. It goes like this:
When I realize I type a command often, I just push the up arrow to get the command again, append "ali" infront of it and turn it to an alias. Works direclty.
And of course the alias to show the list of all aliases:
Have you taken a look at the top dotfiles on Github ( https://dotfiles.github.io/ )? They have a pretty good set of aliases, especially the basics and many for git.
My most used aliases would probably have to be for the git commands.
Each git command, I have aliased to the name of the command, preceded with the letter 'g'. So:
alias gadd='git add'
and so on.
I find the oh-my-zsh git plugin's default aliases to be unintuitive and hard to remember. Simply not having to type 'git ' before everything is good enough for me.
Useful when you have a file picker in front of you, but you know you have a terminal already in the directory you want. Switch to the term, cpcd, switch to the file picker, Go to folder (⌘-Shift-G), Paste (⌘-V).
when you have a terminal open in a directory, but another app has a file picker box.
I've not actually used it as a script in a while, and it appears to be broken in that regard at the moment (something about ld not being able to write to the tmp directory). However, its Makefile is still operational. Maybe someone will see this and submit a PR that fixes it?
Install useful .bashrc shortcuts: u check updates, l detailed file list, .. parent dir, i [appname] install package, x [file] uncompress file, own [dir] get access to folder, p [procname] find process by name, f [string] find string in this folder's files, gg git commit and push