Bash: New aliases + prevent duplicates in $PATH + some refactoring.
This commit is contained in:
parent
5b8ee712c4
commit
38359da2f6
@ -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
|
||||
|
@ -33,6 +33,10 @@
|
||||
|
||||
* *marked* → open -a marked
|
||||
|
||||
* *e* → subl
|
||||
|
||||
* *+x* → chmod +x
|
||||
|
||||
* *md <dir>* → Make directory and `cd` to it.
|
||||
|
||||
* *f <what>* → 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 <URL>
|
||||
|
||||
Print HTTP headers of a given URL.
|
||||
|
||||
### gz <filepath>
|
||||
|
||||
Get gzipped file size.
|
||||
|
@ -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`
|
||||
|
@ -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 <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
|
||||
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.');
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user