Skip to content

Instantly share code, notes, and snippets.

@jvz
Last active December 12, 2015 05:44
Show Gist options
  • Save jvz/25e206918303702ff27b to your computer and use it in GitHub Desktop.
Save jvz/25e206918303702ff27b to your computer and use it in GitHub Desktop.
# vim:syn=sh:ft=sh:
# vim aliases
export EDITOR=vim
alias gvim='open -a /Applications/MacVim.app'
alias se='sudo -e' # sudo edit; make sure $EDITOR is vim or something!
# Directory aliases
alias ..='cd ..' # go back one directory
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
# ls family
alias sl='ls' # typos = gh3y
alias ll='ls -l' # long listing
alias la='ls -A' # all
alias lsd='ls -d */' # see xd
alias xd='ls -dl */' # list directories
# grep family
alias rgrep='grep -r'
alias ergrep='grep -E -r'
# useful shortcuts
alias rwrr='chmod 0644'
alias rmrf='rm -rf'
# one-letter aliases
alias l='ls -F' # list with the general indicators */=@|
alias c='cd;clear' # for quick screen clearing
alias s="[ '$TERM' != 'screen' ] && screen -DR" # quick usage of screen
alias g='git'
__git_complete g __git_main
alias cs="cd;clear;[ '$TERM' != 'screen' ] && screen -DR"
alias what-is-my-ip="curl http://checkip.amazonaws.com/"
alias bubu='brew update && brew upgrade && brew cleanup'
# mini-programs from ~/bin
# back up a file
_backup_file()
{
for f; do
i=0
while [ -e "$f.$i" ]; do
(( i++ ))
done
FLAGS="-fp" # force; preserve mode, ownership, timestamps
if [ -d "$f" ]; then
FLAGS="${FLAGS}r" # recursive
fi
${CP:-cp} $FLAGS "$f" "$f.$i"
echo "Copied to $f.$i"
done
}
backup_file()
{
export CP="cp"
_backup_file "$@"
}
s_backup_file()
{
export CP="sudo cp"
_backup_file "$@"
}
# alternate back-up for files in /etc (idea from Frisch, Aeleen: Essential
# System Administration (3rd edition).)
# use: etc_backup_file <file>
# note: this isn't as useful now that I use etckeeper on all my computers
etc_backup_file()
{
src="$1"
dst="$1.dist"
if [ -e "$dst" ]; then
s_backup_file "$dst"
fi
# XXX: I could modify _backup_file() to handle this via another arg
FLAGS="-fp" # see _backup_file()
if [ -d "$src" ]; then
FLAGS="${FLAGS}r"
fi
sudo cp $FLAGS "$src" "$dst"
sudo chmod a-w "$dst" # don't want to edit the originals, eh?
echo "Copied to $dst"
}
# create an empty executable file (or multiple ones)
create_executable()
{
touch "$@" && chmod a+x "$@"
}
s_create_executable()
{
sudo touch "$@" && sudo chmod a+x "$@"
}
# ping flood network stability test
ping_flood_test()
{
sudo ping -f -c 2000 "$@"
}
# find which program is actually used
# e.g. `which editor` is /usr/bin/editor, but /usr/bin/editor is a symlink
# to /etc/alternatives/editor, and that is a symlink to /usr/bin/vim which is
# a symlink to /usr/bin/vim.full
whichase()
{
chase $( which "$@" )
}
#
# generates an 8 bit color table (256 colors) for reference,
# using the ANSI CSI+SGR \033[48;5;${val}m for background and
# \033[38;5;${val}m for text (see "ANSI Code" on Wikipedia)
#
printAnsiiTable() {
echo -en "\n + "
for i in {0..35}; do
printf "%2b " $i
done
printf "\n\n %3b " 0
for i in {0..15}; do
echo -en "\033[48;5;${i}m \033[m "
done
#for i in 16 52 88 124 160 196 232; do
for i in {0..24}; do
let "i = i*8 +16"
printf "\n\n %3b " $i
for j in {0..35}; do
let "val = i+j"
echo -en "\033[48;5;${val}m \033[m "
done
done
echo -e "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment