Bash: New aliases + prevent duplicates in $PATH + some refactoring.

This commit is contained in:
Artem Sapegin 2012-12-13 16:26:57 +04:00
parent 5b8ee712c4
commit 38359da2f6
5 changed files with 42 additions and 12 deletions

View File

@ -32,8 +32,9 @@ dotfiles
* Sublime Text 2 settings syncronization and packages autoinstall (`setup/sublime-settings.sh` and `setup/sublime-packages.sh`). * Sublime Text 2 settings syncronization and packages autoinstall (`setup/sublime-settings.sh` and `setup/sublime-packages.sh`).
* Consolas font install script (`setup/consolas.sh`) * Consolas font install script (`setup/consolas.sh`)
* Bash4 install script (`setup/bash.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`) * 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) * [Mac OS X apps I use](https://github.com/sapegin/dotfiles/wiki/OS-X-Apps)
## Notes ## Notes

View File

@ -33,6 +33,10 @@
* *marked* → open -a marked * *marked* → open -a marked
* *e* → subl
* *+x* → chmod +x
* *md <dir>* Make directory and `cd` to it. * *md <dir>* Make directory and `cd` to it.
* *f <what>* Recursively find file in current directory. * *f <what>* Recursively find file in current directory.
@ -80,6 +84,10 @@ Get a characters Unicode code point: `£` → `\x00A3`.
Make HTTP request using respective method. Make HTTP request using respective method.
### headers <URL>
Print HTTP headers of a given URL.
### gz <filepath> ### gz <filepath>
Get gzipped file size. Get gzipped file size.

View File

@ -14,7 +14,9 @@ alias pjf="cd ~/Dropbox/Projects/_Forks"
alias pjm="cd ~/Dropbox/Projects/!" alias pjm="cd ~/Dropbox/Projects/!"
alias o="open" alias o="open"
alias oo="open ." alias oo="open ."
alias e="subl"
alias marked="open -a marked" alias marked="open -a marked"
alias +x="chmod +x"
# Detect which `ls` flavor is in use # Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls` if ls --color > /dev/null 2>&1; then # GNU `ls`

View File

@ -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" 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 <URL>
# 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 # Escape UTF-8 characters into their 3-byte format
function escape() { function escape() {
printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u) printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u)
@ -240,7 +250,7 @@ function rasterize() {
[[ $filename != *png ]] && filename="$filename.png" [[ $filename != *png ]] && filename="$filename.png"
phantomjs <(echo " phantomjs <(echo "
var page = new WebPage(); var page = new WebPage();
page.viewportSize = { width: 1280, height_: 1024 }; page.viewportSize = { width: 1280 };
page.open('$url', function (status) { page.open('$url', function (status) {
if (status !== 'success') { if (status !== 'success') {
console.log('Unable to load the address.'); console.log('Unable to load the address.');
@ -257,4 +267,4 @@ function rasterize() {
echo "Screenshot saved to: $filename" echo "Screenshot saved to: $filename"
fi fi
} }

View File

@ -30,11 +30,20 @@ done
export LC_ALL=en_US.UTF-8 export LC_ALL=en_US.UTF-8
export LANG="en_US" 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 # Extend $PATH
[ -d ~/bin ] && PATH="~/bin:$PATH" [ -d /usr/local/bin ] && _prepend_path "/usr/local/bin"
[ -d /usr/local/share/npm/bin ] && PATH="/usr/local/share/npm/bin:$PATH" [ -d /usr/local/share/npm/bin ] && _prepend_path "/usr/local/share/npm/bin"
PATH="/usr/local/bin:$PATH" command -v brew >/dev/null 2>&1 && _prepend_path "$(brew --prefix coreutils)/libexec/gnubin"
command -v brew >/dev/null 2>&1 && PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH" [ -d ~/dotfiles/bin ] && _prepend_path "~/dotfiles/bin"
[ -d ~/bin ] && _prepend_path "~/bin"
export PATH export PATH
# Colors # 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" 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 # 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 [ -e "~/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh
} }
_ssh_reload_autocomplete _ssh_reload_autocomplete
@ -102,9 +111,9 @@ less_options=(
# Do not complain when we are on a dumb terminal. # Do not complain when we are on a dumb terminal.
--dumb --dumb
); );
export LESS="${less_options[*]}"; export LESS="${less_options[*]}"
unset less_options; unset less_options
export PAGER='less'; export PAGER='less'
# Load extra (private) settings # Load extra (private) settings
[ -r "~/.bashlocal" ] && source "~/.bashlocal" [ -f "~/.bashlocal" ] && source "~/.bashlocal"