diff --git a/aliases/available/atom.aliases.bash b/aliases/available/atom.aliases.bash new file mode 100644 index 00000000..e9d427c7 --- /dev/null +++ b/aliases/available/atom.aliases.bash @@ -0,0 +1,5 @@ +cite 'about-alias' +about-alias 'Atom.io editor abbreviations' + +alias a='atom' +alias ah='atom .' diff --git a/aliases/available/docker.aliases.bash b/aliases/available/docker.aliases.bash index 24c21f5b..87b525db 100644 --- a/aliases/available/docker.aliases.bash +++ b/aliases/available/docker.aliases.bash @@ -3,13 +3,13 @@ about-alias 'docker abbreviations' alias dklc='docker ps -l' # List last Docker container alias dklcid='docker ps -l -q' # List last Docker container ID -alias dklcip="docker inspect `dklcid` | grep IPAddress | cut -d '\"' -f 4" # Get IP of last Docker container +alias dklcip="docker inspect `docker ps -l -q` | grep IPAddress | cut -d '\"' -f 4" # Get IP of last Docker container alias dkps='docker ps' # List running Docker containers alias dkpsa='docker ps -a' # List all Docker containers alias dki='docker images' # List Docker images alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container -alias dkrmui='docker rmi $(docker images | grep "^" | awk "{print $3}")' # Delete all untagged Docker images +alias dkrmui='docker images -q -f dangling=true |xargs -r docker rmi' # Delete all untagged Docker images alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz diff --git a/aliases/available/emacs.aliases.bash b/aliases/available/emacs.aliases.bash index 0efcf780..597ae2dd 100644 --- a/aliases/available/emacs.aliases.bash +++ b/aliases/available/emacs.aliases.bash @@ -4,7 +4,10 @@ about-alias 'emacs editor' case $OSTYPE in linux*) alias em='emacs' + alias et='emacs -nw' alias e='emacsclient -n' + alias et='emacsclient -t' + alias ed='emacs --daemon' alias E='SUDO_EDITOR="emacsclient" sudo -e' ;; darwin*) diff --git a/aliases/available/tmux.aliases.bash b/aliases/available/tmux.aliases.bash new file mode 100644 index 00000000..1b07f149 --- /dev/null +++ b/aliases/available/tmux.aliases.bash @@ -0,0 +1,6 @@ +cite 'about-alias' +about-alias 'Tmux terminal multiplexer' + +alias txl='tmux ls' +alias txn='tmux new -s' +alias txa='tmux a -t' diff --git a/aliases/available/vagrant.aliases.bash b/aliases/available/vagrant.aliases.bash index f8ff843f..cfedb657 100644 --- a/aliases/available/vagrant.aliases.bash +++ b/aliases/available/vagrant.aliases.bash @@ -3,6 +3,7 @@ about-alias 'vagrant aliases' # Aliases alias vup="vagrant up" +alias vupl="vagrant up 2>&1 | tee vagrant.log" alias vh="vagrant halt" alias vs="vagrant suspend" alias vr="vagrant resume" diff --git a/completion/available/drush.completion.bash b/completion/available/drush.completion.bash index a65def6f..4f3f784f 100644 --- a/completion/available/drush.completion.bash +++ b/completion/available/drush.completion.bash @@ -7,7 +7,7 @@ # http://github.com/drush-ops/drush/blob/master/drush.complete.sh # Ensure drush is available. -which drush > /dev/null || alias drush &> /dev/null || return +which drush &> /dev/null || alias drush &> /dev/null || return __drush_ps1() { f="${TMPDIR:-/tmp/}/drush-env/drush-drupal-site-$$" diff --git a/lib/helpers.bash b/lib/helpers.bash index 9c4c4dbc..c5ae9cd1 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -361,3 +361,21 @@ all_groups () cat $file | sort | uniq rm $file } + +if ! type pathmunge > /dev/null 2>&1 +then + function pathmunge () { + _about 'prevent duplicate directories in you PATH variable' + _group 'lib helpers' + _example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH' + _example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir' + + if ! [[ $PATH =~ (^|:)$1($|:) ]] ; then + if [ "$2" = "after" ] ; then + export PATH=$PATH:$1 + else + export PATH=$1:$PATH + fi + fi + } +fi diff --git a/plugins/available/aws.plugin.bash b/plugins/available/aws.plugin.bash index 68fc4907..c8920e38 100644 --- a/plugins/available/aws.plugin.bash +++ b/plugins/available/aws.plugin.bash @@ -4,18 +4,14 @@ about-plugin 'AWS helper functions' function awskeys { about 'helper function for AWS credentials file' group 'aws' - if [[ $# -eq 0 ]]; then - __awskeys_help - elif [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then + if [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then __awskeys_list "$2" - elif [[ $# -eq 2 ]]; then - if [[ "$1" = "show" ]]; then - __awskeys_show "$2" - elif [[ "$1" = "export" ]]; then - __awskeys_export "$2" - else - __awskeys_help - fi + elif [[ $# -eq 1 ]] && [[ "$1" = "unset" ]]; then + __awskeys_unset "$2" + elif [[ $# -eq 2 ]] && [[ "$1" = "show" ]]; then + __awskeys_show "$2" + elif [[ $# -eq 2 ]] && [[ "$1" = "export" ]]; then + __awskeys_export "$2" else __awskeys_help fi @@ -26,9 +22,10 @@ function __awskeys_help { echo -e "Helper to AWS credentials file.\n" echo -e "Commands:\n" echo " help Show this help message" - echo " list List available credentials profiles" - echo " show Show the keys associated to a credentials profile" - echo " export Export a credentials profile keys as environment variables" + echo " list List available AWS credentials profiles" + echo " show Show the AWS keys associated to a credentials profile" + echo " export Export an AWS credentials profile keys as environment variables" + echo " unset Unset the AWS keys variables from the environment" } function __awskeys_get { @@ -39,7 +36,7 @@ function __awskeys_get { } function __awskeys_list { - local credentials_list="$(egrep '^\[ *[a-zA-Z0-0_-]+ *\]$' ~/.aws/credentials)" + local credentials_list="$(egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials)" if [[ -n $"{credentials_list}" ]]; then echo -e "Available credentials profiles:\n" for cred in ${credentials_list}; do @@ -61,12 +58,18 @@ function __awskeys_show { } function __awskeys_export { - local p_keys="$(__awskeys_get $1)" + local p_keys=( $(__awskeys_get $1 | tr -d " ") ) if [[ -n "${p_keys}" ]]; then - eval $(echo "${p_keys}" | tr -d " " | sed -r -e "s/(.+=)(.+)/export \U\1\E\2/") + for p_key in ${p_keys[@]}; do + local key="${p_key%=*}" + export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}" + done export AWS_DEFAULT_PROFILE="$1" else echo "Profile $1 not found in credentials file" fi } +function __awskeys_unset { + unset AWS_DEFAULT_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY +} diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index aa35a708..accd3610 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -5,7 +5,15 @@ function ips () { about 'display all ip addresses for this host' group 'base' - ifconfig | awk '/inet /{ print $2 }' + if command -v ifconfig &>/dev/null + then + ifconfig | awk '/inet /{ print $2 }' + elif command -v ip &>/dev/null + then + ip addr | grep -oP 'inet \K[\d.]+' + else + echo "You don't have ifconfig or ip command installed!" + fi } function down4me () diff --git a/plugins/available/history.plugin.bash b/plugins/available/history.plugin.bash index 512bbf92..386e05d1 100644 --- a/plugins/available/history.plugin.bash +++ b/plugins/available/history.plugin.bash @@ -1,4 +1,7 @@ # enter a few characters and press UpArrow/DownArrow # to search backwards/forwards through the history -bind '"":history-search-backward' -bind '"":history-search-forward' +if [ -t 1 ]; +then + bind '"":history-search-backward' + bind '"":history-search-forward' +fi diff --git a/plugins/available/nginx.plugin.bash b/plugins/available/nginx.plugin.bash index 8e8b7346..c540a23a 100644 --- a/plugins/available/nginx.plugin.bash +++ b/plugins/available/nginx.plugin.bash @@ -1,11 +1,8 @@ cite about-plugin about-plugin 'manage your nginx service' -# Set the path nginx export NGINX_PATH='/opt/nginx' - -# Add nginx to the path -export PATH=$PATH:$NGINX_PATH/sbin +pathmunge $NGINX_PATH/sbin after function nginx_reload() { about 'reload your nginx config' diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 06b158e7..f0467cef 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,9 +1,7 @@ cite about-plugin about-plugin 'Node.js helper functions' -export PATH=./node_modules/.bin:$PATH +pathmunge ./node_modules/.bin # Make sure the global npm prefix is on the path -[[ `which npm` ]] && export PATH=$(npm config get prefix)/bin:$PATH - - +[[ `which npm` ]] && pathmunge $(npm config get prefix)/bin diff --git a/plugins/available/python.plugin.bash b/plugins/available/python.plugin.bash index 51970786..ad7e4069 100644 --- a/plugins/available/python.plugin.bash +++ b/plugins/available/python.plugin.bash @@ -1,11 +1,11 @@ cite about-plugin -about-plugin 'alias "http" to SimpleHTTPServer' +about-plugin 'alias "shttp" to SimpleHTTPServer' if [ $(uname) = "Linux" ] then - alias http='python2 -m SimpleHTTPServer' + alias shttp='python2 -m SimpleHTTPServer' else - alias http='python -m SimpleHTTPServer' + alias shttp='python -m SimpleHTTPServer' fi function pyedit() { diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 232a2a8e..6940b9ee 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -55,8 +55,7 @@ function set_rgb_color { function powerline_shell_prompt { SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR} - CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1 | grep "load" | wc -l) - if [ ${CAN_I_RUN_SUDO} -gt 0 ]; then + if sudo -n uptime 2>&1 | grep -q "load"; then SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR_SUDO} fi SEGMENT_AT_RIGHT=0 diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 1bc4eca9..944414db 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -4,7 +4,7 @@ THEME_PROMPT_SEPARATOR="" SHELL_SSH_CHAR=" " SHELL_THEME_PROMPT_COLOR=32 -SHELL_SSH_THEME_PROMPT_COLOR=208 +SHELL_THEME_PROMPT_COLOR_SUDO=202 VIRTUALENV_CHAR="ⓔ " VIRTUALENV_THEME_PROMPT_COLOR=35 @@ -37,13 +37,17 @@ function set_rgb_color { } function powerline_shell_prompt { - if [[ -n "${SSH_CLIENT}" ]]; then - SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}" - LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR} - else - SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}" - LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR} + SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR} + if sudo -n uptime 2>&1 | grep -q "load"; then + SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR_SUDO} fi + if [[ -n "${SSH_CLIENT}" ]]; then + SHELL_PROMPT="${SHELL_SSH_CHAR}\u@\h" + else + SHELL_PROMPT="\u" + fi + SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}" + LAST_THEME_COLOR=${SHELL_PROMPT_COLOR} } function powerline_virtualenv_prompt {