Skip to content

Instantly share code, notes, and snippets.

@benyarb
Created May 15, 2012 21:55
Show Gist options
  • Save benyarb/2705452 to your computer and use it in GitHub Desktop.
Save benyarb/2705452 to your computer and use it in GitHub Desktop.
My .bashrc File (Mac)
# ~/.bashrc
#----------------
# Aliases
#----------------
# Prompt overwrites
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Show hidden files
alias la='ls -a'
# Show files and permissions
alias ll='ls -l'
#----------------
# Functions
#----------------
# Create a directory and immediately enter it
function mkcd() {
if [ ! -n "$1" ]; then
echo "Enter a directory name"
elif [ -d $1 ]; then
echo "\`$1' already exists"
else
mkdir $1 && cd $1
fi
}
# Enter a directory and list the contents
function cs() {
cd "$1" && ls
}
# Enter a directory and list the contents (include hidden)
function ca() {
cd "$1" && ls -a
}
# Enter a directory and list the contents with permissions
function cl() {
cd "$1" && ls -l
}
# Extract compressed files of various formats with 1 command
function extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Display files in Quick Look
function ql() {
(qlmanage -p "$@" > /dev/null 2>&1 &
local ql_pid=$!
read -sn 1
kill ${ql_pid}) > /dev/null 2>&1
}
# Display any filetype as plain text in Quick Look
function qlt() {
(qlmanage -p -c public.plain-text "$@" > /dev/null 2>&1 &
local ql_pid=$!
read -sn 1
kill ${ql_pid}) > /dev/null 2>&1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment