Last active
January 23, 2019 07:35
-
-
Save suewonjp/acd522d633c4ad8feed83d333c33dfdc to your computer and use it in GitHub Desktop.
My Bash aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ "Darwin" == $(uname) ]; then | |
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app' | |
alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app' | |
alias hibernateMode='sudo pmset -a hibernatemode 25' | |
alias sleepMode='sudo pmset -a hibernatemode 3' | |
alias f='open -a Finder ' | |
fi | |
## Save keystrokes for directory navigation | |
alias ~='cd ~' | |
alias ..='cd ..' | |
alias ...='cd ../..' | |
alias ....='cd ../../..' | |
alias .5='cd ../../../../' | |
alias .6='cd ../../../../..' | |
alias .7='cd ../../../../../..' | |
## Clear the terminal screen | |
alias c='clear' | |
## Create a directory hierarchy | |
alias mkdir='mkdir -pv' | |
alias grep='grep --color=always ' | |
## Print list of $PATH | |
alias path='echo -e ${PATH//:/\\n}' | |
## Obtain the current date & time | |
alias now='date "+DATE: %y/%m/%d%nTIME: %H:%M:%S"' | |
alias d-t='date "+%y-%m-%d_%Hh%Mm%Ss"' | |
## Backup an arbitrary file/folder | |
## usage) bu [file or folder] | |
alias bu='f_bu() { cp -R "$1" "$1"-`d-t`; }; f_bu' | |
## Show files with a long listing format | |
alias ll='ls -laF' | |
## Show hidden files | |
alias l.='ls -d .*' | |
## Print a long bar as follows | |
## | |
## ================================================================================ | |
## | |
## When your screen is cluttered with lots of messages, | |
## this will let you easily spot a particular portion of messages | |
alias l='tput setaf 5 && printf "\n%80s\n\n" | tr " " = && tput sgr 0' | |
## Show total size of all the target folder contents | |
## usage) d [file or folder] | |
alias d='du -sh' | |
## List files and folders and sort them by size (kb units) | |
alias ds='du -sk * | sort -nr' | |
## Print exit code from the last run command | |
alias e='echo $?' | |
alias wd='pwd | sed "s@/@ / @g"' | |
## Print remaining battery power | |
if [ "Linux" == "$(uname)" ]; then | |
alias battery='cat /sys/class/power_supply/BAT0/capacity' | |
fi | |
## Define pbcopy for copying data to the system clipboard | |
## and pbpaste for pasting data from the system clipboard | |
## As you may know, OS X already has them. | |
## In Linux, you need to install xsel or xclip | |
type pbcopy > /dev/null 2>&1 && pbpaste > /dev/null 2>&1 || { | |
case "$( uname )" in | |
CYGWIN*) | |
alias pbcopy='cat - > /dev/clipboard' | |
alias pbpaste='cat /dev/clipboard' | |
;; | |
*) | |
if type xsel > /dev/null 2>&1; then | |
alias pbcopy='xsel --clipboard --input' | |
alias pbpaste='xsel --clipboard --output' | |
elif type xclip > /dev/null 2>&1; then | |
alias pbcopy='xclip -selection clipboard' | |
alias pbpaste='xclip -selection clipboard -o' | |
else | |
: ### Dump some error or warning messages here; | |
fi | |
;; | |
esac | |
} | |
if type pbcopy &> /dev/null && type pbpaste &> /dev/null; then | |
copyToClipboard() { | |
[ $# -lt 1 ] && echo "Usage: $FUNCNAME [text to copy]" && return; | |
echo -n $@ | pbcopy | |
} | |
## Copy arbitrary command output to the system clipboard | |
## e.g) echo hello world |~~ | |
alias ~~='copyToClipboard $( cat - ); pbpaste; echo' | |
## Copy the current working directory path to the system clipboard | |
alias cwd='echo ~+|~~' | |
fi | |
## Rerun the last command (shorter than '!!') | |
alias r='fc -s' | |
## Open with Vim the files whose names have been written to the STDOUT by the last command | |
alias vl='vim -p $(fc -s)' | |
## Invoke vim even when asked for vi | |
alias vi=vim | |
## Print the current git branch (available in only git repositories) | |
alias cb='git symbolic-ref HEAD | cut -d"/" -f3' | |
## Invoke diff with unified mode | |
alias diff='diff -u' | |
## Launch a simple http web server | |
## 'http-server' node module should be installed | |
alias ws='hs -s -a localhost -p 8000 -c-1 ./' | |
## Numeric calculation | |
## e.g) % "(3+4)*2" | |
alias %='bc -l <<<' | |
## Converting numbers to decimal format | |
## e.g) dec 0x7fffffff | |
alias dec='printf "%d\n"' | |
## Converting numbers to hexadecimal format | |
## e.g) hex 0x7fffffff | |
alias hex='printf "%x\n"' | |
## Convert tabs to spaces for system clipboard content | |
## Need to properly define pbcopy/pbpaste aliases | |
alias t2s='pbpaste | expand | pbcopy' | |
## Bash completion for alias names | |
## e.g) Just typing 'alias l <tab><tab>' will suggest every aliases that start with 'l' | |
## Convenient when you don't remember the whole name of the alias you need for the moment | |
complete -A alias "alias" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment