diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..d4c710cb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.sh text eol=lf +*.bash text eol=lf diff --git a/README.md b/README.md index b2ad2d88..6219d636 100644 --- a/README.md +++ b/README.md @@ -140,17 +140,28 @@ For custom scripts, and aliases, just create the following files (they'll be ign Anything in the custom directory will be ignored, with the exception of `custom/example.bash`. -Alternately, if you would like to keep your custom scripts under version control, you can set BASH_IT_CUSTOM in your `~/.bashrc` to another location outside of the `~/.bash_it` folder. +Alternately, if you would like to keep your custom scripts under version control, you can set `BASH_IT_CUSTOM` in your `~/.bashrc` to another location outside of the `~/.bash_it` folder. ## Themes -There are a few Bash-it themes. If you've created your own custom prompts, I'd love it if you shared with everyone else! Just submit a Pull Request. +There are over 50+ Bash-it themes to pick from in `.bash_it/themes`. The default theme is `bobby`. Set `BASH_IT_THEME` to the theme name you want, or if you've developed your own custom theme outside of `.bash_it/themes`, point the `BASH_IT_THEME` variable directly to the theme file. -You can see the theme screenshots [here](https://github.com/Bash-it/bash-it/wiki/Themes). +Examples: -Alternatively, you can preview the themes in your own shell using `BASH_PREVIEW=true reload`. +```bash +# Use the "powerline-multiline" theme +export BASH_IT_THEME="powerline-multiline" -**NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid extrange behaviors in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if isn't American English. +# Use a theme outside of the Bash-it folder +export BASH_IT_THEME="/home/foo/my_theme/my_theme.theme.bash" +``` + +You can easily preview the themes in your own shell using `BASH_PREVIEW=true reload`. + +If you've created your own custom prompts, we'd love it if you shared with everyone else! Just submit a Pull Request. +You can see theme screenshots on [wiki/Themes](https://github.com/Bash-it/bash-it/wiki/Themes). + +**NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid strange behavior in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if isn't American English. ## Uninstalling diff --git a/aliases/available/docker.aliases.bash b/aliases/available/docker.aliases.bash index bb9f99ca..7d837c70 100644 --- a/aliases/available/docker.aliases.bash +++ b/aliases/available/docker.aliases.bash @@ -10,6 +10,7 @@ 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 images -q -f dangling=true |xargs -r docker rmi' # Delete all untagged Docker images +alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers 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/general.aliases.bash b/aliases/available/general.aliases.bash index 38a8bfe6..a4cf4ee2 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -71,6 +71,13 @@ fi alias md='mkdir -p' alias rd='rmdir' +# Common misspellings of bash-it +alias shit='bash-it' +alias batshit='bash-it' +alias bashit='bash-it' +alias bash_it='bash-it' +alias bash_ti='bash-it' + # Display whatever file is regular file or folder catt() { for i in "$@"; do diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 2fe26b12..55b5988b 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -15,6 +15,7 @@ alias gus='git reset HEAD' alias gpristine='git reset --hard && git clean -dfx' alias gclean='git clean -fd' alias gm="git merge" +alias gmv='git mv' alias g='git' alias get='git' alias gst='git status' @@ -33,6 +34,7 @@ alias gpom='git push origin master' alias gr='git remote' alias grv='git remote -v' alias gra='git remote add' +alias gd='git diff' alias gdv='git diff -w "$@" | vim -R -' alias gc='git commit -v' alias gca='git commit -v -a' @@ -42,6 +44,7 @@ alias gcam='git commit -a -m' alias gb='git branch' alias gba='git branch -a' alias gbt='git branch --track' +alias gbm='git branch -m' alias gcount='git shortlog -sn' alias gcp='git cherry-pick' alias gco='git checkout' @@ -67,6 +70,10 @@ alias gnew="git log HEAD@{1}..HEAD@{0}" # Add uncommitted and unstaged changes to the last commit alias gcaa="git commit -a --amend -C HEAD" alias ggui="git gui" +alias gcam="git commit -am" +alias gcsam="git commit -S -am" +alias gstd="git stash drop" +alias gstl="git stash list" case $OSTYPE in darwin*) @@ -76,19 +83,3 @@ case $OSTYPE in alias gtls='git tag -l | sort -V' ;; esac - -if [ -z "$EDITOR" ]; then - case $OSTYPE in - linux*) - alias gd='git diff | vim -R -' - ;; - darwin*) - alias gd='git diff | mate' - ;; - *) - alias gd='git diff' - ;; - esac -else - alias gd="git diff | $EDITOR" -fi diff --git a/aliases/available/npm.aliases.bash b/aliases/available/npm.aliases.bash index b01241e7..4623c738 100644 --- a/aliases/available/npm.aliases.bash +++ b/aliases/available/npm.aliases.bash @@ -10,7 +10,7 @@ alias nits='npm install-test --save' alias nitd='npm install-test --save-dev' alias nu='npm uninstall' alias nus='npm uninstall --save' -alias nud='npm uninstall --save-dev' +alias nusd='npm uninstall --save-dev' alias np='npm publish' alias nup='npm unpublish' alias nlk='npm link' diff --git a/aliases/available/osx.aliases.bash b/aliases/available/osx.aliases.bash index 3d09605e..5e30bc7c 100644 --- a/aliases/available/osx.aliases.bash +++ b/aliases/available/osx.aliases.bash @@ -18,7 +18,7 @@ alias textedit='open -a TextEdit' alias hex='open -a "Hex Fiend"' alias skype='open -a Skype' alias mou='open -a Mou' -alias subl='open -a Sublime\ Text --args' +alias subl='open -a Sublime\ Text' if [ -s /usr/bin/firefox ] ; then unalias firefox diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index f4326a0a..edcad0ea 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -110,4 +110,10 @@ _bash-it-comp() return 0 } +# Activate completion for bash-it and its common misspellings complete -F _bash-it-comp bash-it +complete -F _bash-it-comp bash-ti +complete -F _bash-it-comp shit +complete -F _bash-it-comp bashit +complete -F _bash-it-comp batshit +complete -F _bash-it-comp bash_it diff --git a/completion/available/ng.completion.bash b/completion/available/ng.completion.bash new file mode 100644 index 00000000..cd191bb2 --- /dev/null +++ b/completion/available/ng.completion.bash @@ -0,0 +1,3 @@ + +. <(ng completion --bash) + diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash new file mode 100644 index 00000000..1800756b --- /dev/null +++ b/completion/available/pip3.completion.bash @@ -0,0 +1,11 @@ + +# pip bash completion start +_pip_completion() +{ + COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + PIP_AUTO_COMPLETE=1 $1 ) ) +} +complete -o default -F _pip_completion pip3 +# pip bash completion end + diff --git a/completion/available/rvm.completion.bash b/completion/available/rvm.completion.bash new file mode 100644 index 00000000..cd8ded04 --- /dev/null +++ b/completion/available/rvm.completion.bash @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Bash completion support for RVM. +# Source: https://rvm.io/workflow/completion + +[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion diff --git a/lib/appearance.bash b/lib/appearance.bash index 48134c98..6d0ef2ff 100644 --- a/lib/appearance.bash +++ b/lib/appearance.bash @@ -9,7 +9,9 @@ fi # Load the theme if [[ $BASH_IT_THEME ]]; then - if [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then + if [[ -f $BASH_IT_THEME ]]; then + source $BASH_IT_THEME + elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" else source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" diff --git a/plugins/available/docker.plugin.bash b/plugins/available/docker.plugin.bash index 4a2abbd7..2632c3cc 100644 --- a/plugins/available/docker.plugin.bash +++ b/plugins/available/docker.plugin.bash @@ -4,13 +4,20 @@ about-plugin 'Helpers to more easily work with Docker' function docker-remove-most-recent-container() { about 'attempt to remove the most recent container from docker ps -a' group 'docker' - docker ps -a | head -2 | tail -1 | awk '{print $NF}' | xargs docker rm + docker ps -ql | xargs docker rm } function docker-remove-most-recent-image() { about 'attempt to remove the most recent image from docker images' group 'docker' - docker images | head -2 | tail -1 | awk '{print $3}' | xargs docker rmi + docker images -q | head -1 | xargs docker rmi +} + +function docker-remove-stale-assets() { + about 'attempt to remove exited containers and dangling images' + group 'docker' + docker ps --filter status=exited -q | xargs docker rm --volumes + docker images --filter dangling=true -q | xargs docker rmi } function docker-enter() { diff --git a/plugins/available/python.plugin.bash b/plugins/available/python.plugin.bash index ad7e4069..ceba6268 100644 --- a/plugins/available/python.plugin.bash +++ b/plugins/available/python.plugin.bash @@ -14,7 +14,7 @@ function pyedit() { example '$ pyedit requests' group 'python' - xpyc=`python -c "import sys; stdout = sys.stdout; sys.stdout = sys.stderr; import $1; stdout.write($1.__file__)"` + xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"` if [ "$xpyc" == "" ]; then echo "Python module $1 not found" diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 6d32dc14..a376fffd 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -20,6 +20,8 @@ SCM_THEME_BRANCH_TRACK_PREFIX=' → ' SCM_THEME_BRANCH_GONE_PREFIX=' ⇢ ' SCM_THEME_CURRENT_USER_PREFFIX=' ☺︎ ' SCM_THEME_CURRENT_USER_SUFFIX='' +SCM_THEME_CHAR_PREFIX='' +SCM_THEME_CHAR_SUFFIX='' THEME_BATTERY_PERCENTAGE_CHECK=${THEME_BATTERY_PERCENTAGE_CHECK:=true} @@ -92,6 +94,16 @@ function scm_prompt_vars { function scm_prompt_info { scm scm_prompt_char + scm_prompt_info_common +} + +function scm_prompt_char_info { + scm_prompt_char + echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" + scm_prompt_info_common +} + +function scm_prompt_info_common { SCM_DIRTY=0 SCM_STATE='' @@ -429,7 +441,7 @@ function hg_prompt_info() { function scm_char { scm_prompt_char - echo -e "$SCM_CHAR" + echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" } function prompt_char { diff --git a/themes/bobby/bobby.theme.bash b/themes/bobby/bobby.theme.bash index 1c78025c..0e70f8a6 100644 --- a/themes/bobby/bobby.theme.bash +++ b/themes/bobby/bobby.theme.bash @@ -2,7 +2,7 @@ SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" -SCM_THEME_PROMPT_PREFIX=" |" +SCM_THEME_PROMPT_PREFIX=" ${green}|" SCM_THEME_PROMPT_SUFFIX="${green}|" GIT_THEME_PROMPT_DIRTY=" ${red}✗" @@ -23,7 +23,7 @@ __bobby_clock() { function prompt_command() { #PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} " - PS1="\n$(battery_char) $(__bobby_clock)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " + PS1="\n$(battery_char) $(__bobby_clock)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_prompt_char_info) ${green}→${reset_color} " } THEME_SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"} diff --git a/themes/colors.theme.bash b/themes/colors.theme.bash index da42f66b..53f357e2 100644 --- a/themes/colors.theme.bash +++ b/themes/colors.theme.bash @@ -189,7 +189,7 @@ yellow="\[\e[0;33m\]" blue="\[\e[0;34m\]" purple="\[\e[0;35m\]" cyan="\[\e[0;36m\]" -white="\[\e[0;37;1m\]" +white="\[\e[0;37m\]" orange="\[\e[0;91m\]" bold_black="\[\e[30;1m\]" diff --git a/themes/font/font.theme.bash b/themes/font/font.theme.bash new file mode 100644 index 00000000..679528e7 --- /dev/null +++ b/themes/font/font.theme.bash @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# +# One line prompt showing the following configurable information +# for git: +# time (virtual_env) username@hostname pwd git_char|git_branch git_dirty_status|→ +# +# The → arrow shows the exit status of the last command: +# - bold green: 0 exit status +# - bold red: non-zero exit status +# +# Example outside git repo: +# 07:45:05 user@host ~ → +# +# Example inside clean git repo: +# 07:45:05 user@host .bash_it ±|master|→ +# +# Example inside dirty git repo: +# 07:45:05 user@host .bash_it ±|master ✗|→ +# +# Example with virtual environment: +# 07:45:05 (venv) user@host ~ → +# + +SCM_NONE_CHAR='' +SCM_THEME_PROMPT_DIRTY=" ${red}✗" +SCM_THEME_PROMPT_CLEAN="" +SCM_THEME_PROMPT_PREFIX="${green}|" +SCM_THEME_PROMPT_SUFFIX="${green}|" +SCM_GIT_SHOW_MINIMAL_INFO=true + +CLOCK_THEME_PROMPT_PREFIX='' +CLOCK_THEME_PROMPT_SUFFIX=' ' +THEME_SHOW_CLOCK=true +THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_blue"} +THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"} + +VIRTUALENV_THEME_PROMPT_PREFIX='(' +VIRTUALENV_THEME_PROMPT_SUFFIX=') ' + +function prompt_command() { + # This needs to be first to save last command return code + local RC="$?" + + hostname="${bold_black}\u@\h" + virtualenv="${white}$(virtualenv_prompt)" + + # Set return status color + if [[ ${RC} == 0 ]]; then + ret_status="${bold_green}" + else + ret_status="${bold_red}" + fi + + # Append new history lines to history file + history -a + + PS1="$(clock_prompt)${virtualenv}${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}" +} + +safe_append_prompt_command prompt_command diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 9ee38271..d0a46815 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -4,6 +4,8 @@ A colorful theme, where shows a lot information about your shell session. **IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator. +**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where `sudo` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your `~/.bashrc` or `~/.bash_profile` to disable the Powerline theme's `sudo` check. This will apply to all `powerline*` themes. + ## Provided Information * Current path diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 3abeda8d..f65e9dd6 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -1,4 +1,8 @@ +# Define this here so it can be used by all of the Powerline themes +THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} + function set_color { + set +u if [[ "${1}" != "-" ]]; then fg="38;5;${1}" fi @@ -10,11 +14,14 @@ function set_color { } function __powerline_user_info_prompt { + set +u local user_info="" local color=${USER_INFO_THEME_PROMPT_COLOR} - if sudo -n uptime 2>&1 | grep -q "load"; then - color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + if [[ "${THEME_CHECK_SUDO}" = true ]]; then + if sudo -n uptime 2>&1 | grep -q "load"; then + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi fi case "${POWERLINE_PROMPT_USER_INFO_MODE}" in "sudo") @@ -46,6 +53,7 @@ function __powerline_ruby_prompt { } function __powerline_python_venv_prompt { + set +u local python_venv="" if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index b75d3f8f..c18e20b2 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -8,6 +8,9 @@ SCM_GIT_CHAR="${green}±${normal}" SCM_SVN_CHAR="${bold_cyan}⑆${normal}" SCM_HG_CHAR="${bold_red}☿${normal}" +VIRTUALENV_THEME_PROMPT_PREFIX="(" +VIRTUALENV_THEME_PROMPT_SUFFIX=")" + ### TODO: openSUSE has already colors enabled, check if those differs from stock # LS colors, made with http://geoff.greer.fm/lscolors/ # export LSCOLORS="Gxfxcxdxbxegedabagacad" @@ -33,9 +36,9 @@ pure_prompt() { # make it work case $(id -u) in - 0) PS1="$ps_root@$ps_host$(scm_prompt):$ps_path$ps_root_mark" + 0) PS1="$(virtualenv_prompt)$ps_root@$ps_host$(scm_prompt):$ps_path$ps_root_mark" ;; - *) PS1="$ps_user@$ps_host$(scm_prompt):$ps_path$ps_user_mark" + *) PS1="$(virtualenv_prompt)$ps_user@$ps_host$(scm_prompt):$ps_path$ps_user_mark" ;; esac }