diff --git a/Readme.md b/Readme.md index 104b6e5..0a5b526 100644 --- a/Readme.md +++ b/Readme.md @@ -32,8 +32,9 @@ dotfiles * Sublime Text 2 settings syncronization and packages autoinstall (`setup/sublime-settings.sh` and `setup/sublime-packages.sh`). * Consolas font install script (`setup/consolas.sh`) * Bash4 install script (`setup/bash.sh`) -* Homebrew bootstrap (`setup/brew.sh`) +* OS X, Homebrew, NPM, etc. update script (`setup/update.sh`) * My magic project opener (`bin/opener.py`) +* [Bash](https://github.com/sapegin/dotfiles/blob/master/docs/Bash.md) & [Git](https://github.com/sapegin/dotfiles/blob/master/docs/Git.md) aliases and scripts * [Mac OS X apps I use](https://github.com/sapegin/dotfiles/wiki/OS-X-Apps) ## Notes diff --git a/docs/Bash.md b/docs/Bash.md index 7ccef7f..0123ed4 100644 --- a/docs/Bash.md +++ b/docs/Bash.md @@ -33,6 +33,10 @@ * *marked* → open -a marked +* *e* → subl + +* *+x* → chmod +x + * *md * → Make directory and `cd` to it. * *f * → Recursively find file in current directory. @@ -80,6 +84,10 @@ Get a character’s Unicode code point: `£` → `\x00A3`. Make HTTP request using respective method. +### headers + +Print HTTP headers of a given URL. + ### gz Get gzipped file size. diff --git a/includes/bash_aliases.bash b/includes/bash_aliases.bash index c116935..3f93d04 100644 --- a/includes/bash_aliases.bash +++ b/includes/bash_aliases.bash @@ -14,7 +14,9 @@ alias pjf="cd ~/Dropbox/Projects/_Forks" alias pjm="cd ~/Dropbox/Projects/!" alias o="open" alias oo="open ." +alias e="subl" alias marked="open -a marked" +alias +x="chmod +x" # Detect which `ls` flavor is in use if ls --color > /dev/null 2>&1; then # GNU `ls` diff --git a/includes/bash_functions.bash b/includes/bash_functions.bash index ec73f4d..b84a016 100644 --- a/includes/bash_functions.bash +++ b/includes/bash_functions.bash @@ -27,6 +27,16 @@ function httpcompression() { encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" } +# Show HTTP headers for given URL +# Usage: headers +# https://github.com/rtomayko/dotfiles/blob/rtomayko/bin/headers +function headers() { + curl -sv -H "User-Agent: Mozilla/5 Gecko" "$@" 2>&1 >/dev/null | + grep -v "^\*" | + grep -v "^}" | + cut -c3- +} + # Escape UTF-8 characters into their 3-byte format function escape() { printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u) @@ -240,7 +250,7 @@ function rasterize() { [[ $filename != *png ]] && filename="$filename.png" phantomjs <(echo " var page = new WebPage(); - page.viewportSize = { width: 1280, height_: 1024 }; + page.viewportSize = { width: 1280 }; page.open('$url', function (status) { if (status !== 'success') { console.log('Unable to load the address.'); @@ -257,4 +267,4 @@ function rasterize() { echo "Screenshot saved to: $filename" fi -} \ No newline at end of file +} diff --git a/tilde/bash_profile.bash b/tilde/bash_profile.bash index 2896f12..0e165ea 100644 --- a/tilde/bash_profile.bash +++ b/tilde/bash_profile.bash @@ -30,11 +30,20 @@ done export LC_ALL=en_US.UTF-8 export LANG="en_US" + +# Prepend $PATH without duplicates +function _prepend_path() { + if ! $( echo "$PATH" | tr ":" "\n" | grep -qx "$1" ) ; then + PATH="$1:$PATH" + fi +} + # Extend $PATH -[ -d ~/bin ] && PATH="~/bin:$PATH" -[ -d /usr/local/share/npm/bin ] && PATH="/usr/local/share/npm/bin:$PATH" -PATH="/usr/local/bin:$PATH" -command -v brew >/dev/null 2>&1 && PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH" +[ -d /usr/local/bin ] && _prepend_path "/usr/local/bin" +[ -d /usr/local/share/npm/bin ] && _prepend_path "/usr/local/share/npm/bin" +command -v brew >/dev/null 2>&1 && _prepend_path "$(brew --prefix coreutils)/libexec/gnubin" +[ -d ~/dotfiles/bin ] && _prepend_path "~/dotfiles/bin" +[ -d ~/bin ] && _prepend_path "~/bin" export PATH # Colors @@ -64,7 +73,7 @@ unset file command -v brew >/dev/null 2>&1 && [ -r "$(brew --prefix)/etc/bash_completion" ] && source "$(brew --prefix)/etc/bash_completion" # Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards -_ssh_reload_autocomplete() { +function _ssh_reload_autocomplete() { [ -e "~/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh } _ssh_reload_autocomplete @@ -102,9 +111,9 @@ less_options=( # Do not complain when we are on a dumb terminal. --dumb ); -export LESS="${less_options[*]}"; -unset less_options; -export PAGER='less'; +export LESS="${less_options[*]}" +unset less_options +export PAGER='less' # Load extra (private) settings -[ -r "~/.bashlocal" ] && source "~/.bashlocal" +[ -f "~/.bashlocal" ] && source "~/.bashlocal"