From 15177a20d4e93099bd1e80860b39fc90c4b846f6 Mon Sep 17 00:00:00 2001 From: Rod Treweek Date: Mon, 26 Jun 2017 10:56:13 -0700 Subject: [PATCH] Add new feature (#6) * alias additions * Adding powerline-r theme --- aliases/available/general.aliases.bash | 50 +++++++++++----- aliases/available/vagrant.aliases.bash | 5 +- themes/powerline-r/README.md | 59 +++++++++++++++++++ themes/powerline-r/powerline-r.base.bash | 62 ++++++++++++++++++++ themes/powerline-r/powerline-r.theme.bash | 69 +++++++++++++++++++++++ 5 files changed, 229 insertions(+), 16 deletions(-) create mode 100644 themes/powerline-r/README.md create mode 100644 themes/powerline-r/powerline-r.base.bash create mode 100644 themes/powerline-r/powerline-r.theme.bash diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index abab71ed..9cdb8b61 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -18,6 +18,22 @@ alias l1='ls -1' alias _="sudo" +# Shortcuts to edit startup files +alias vigen="vim ~/.bash_it/aliases/available/general.aliases.bash" +alias vbrc="vim ~/.bashrc" +alias vbpf="vim ~/.bash_profile" + +# vmpooler +function vm-grab() { + printf "Hello! You rule. Which vm would you like?: " + read vm_msg + LDAP_USERNAME=rod LDAP_PASSWORD=$(python -c 'import getpass;print(getpass.getpass())') vmpool grab "$vm_msg" +} + +function vm-list() { +LDAP_USERNAME=rod LDAP_PASSWORD=$(python -c 'import getpass;print(getpass.getpass())') vmpool list +} + # colored grep # Need to check an existing file for a pattern that will be found to ensure # that the check works when on an OS that supports the color option @@ -72,29 +88,35 @@ 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 bsh='bash-it' +alias batbsh='bash-it' +alias babsh='bash-it' alias bash_it='bash-it' alias bash_ti='bash-it' alias bsh='bash-it' # Additional bash-it aliases for help/show -alias shitsha='bash-it show aliases' -alias shitshc='bash-it show completions' -alias shitshp='bash-it show plugs' -alias shitha='bash-it help aliases' -alias shithc='bash-it help completions' -alias shithp='bash-it help plugins' -alias shitsrch="bash-it search $1" -alias shitsrchen="bash-it search $1 --enable" -alias shitenp="bash-it enable plugin" -alias shitena="bash-it enable alias" -alias shitenc="bash-it enable completion" +alias bshsa='bash-it show aliases' +alias bshsc='bash-it show completions' +alias bshsp='bash-it show plugins' +alias bshha='bash-it help aliases' +alias bshhc='bash-it help completions' +alias bshhp='bash-it help plugins' +alias bshsch="bash-it search $1" +alias bshschen="bash-it search $1 --enable" +alias bshenp="bash-it enable plugin" +alias bshena="bash-it enable alias" +alias bshenc="bash-it enable completion" + +# Shorten extract +alias xt="extract" # source ~/.bash_profile alias sprof="source ~/.bash_profile" +# sudo vim +alias svim="sudo vim" + # Display whatever file is regular file or folder catt() { for i in "$@"; do diff --git a/aliases/available/vagrant.aliases.bash b/aliases/available/vagrant.aliases.bash index ebbddaf4..ee33ada6 100644 --- a/aliases/available/vagrant.aliases.bash +++ b/aliases/available/vagrant.aliases.bash @@ -7,8 +7,8 @@ alias vscp='vaagrant scp' alias vsl='vagrant snapshot list' alias vst='vagrant snapshot take' alias vup="vagrant up" -alias vupo="vagrant up $1 --provider=openstack" -alias vupv="vagrant up $1 --provider=vsphere" +alias vupo="vagrant up $@ --provider=openstack" +alias vupv="vagrant up $@ --provider=vsphere" alias vupl="vagrant up 2>&1 | tee vagrant.log" alias vh="vagrant halt" alias vs="vagrant suspend" @@ -21,3 +21,4 @@ alias vdstr="vagrant destroy" alias vl="vagrant list" # requires vagrant-hostmanager plugin alias vhst="vagrant hostmanager" +alias svop="source openrc.sh && source vsphere-rc.sh" diff --git a/themes/powerline-r/README.md b/themes/powerline-r/README.md new file mode 100644 index 00000000..af84b4e8 --- /dev/null +++ b/themes/powerline-r/README.md @@ -0,0 +1,59 @@ +# Powerline Multiline Theme + +A colorful multiline theme, where the first line shows information about your shell session (divided into two parts, left and right), and the second one is where the shell commands are introduced. + +**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. + +## Provided Information + +* Current path +* Current username and hostname +* Current time +* An indicator when connected by SSH +* An indicator when `sudo` has the credentials cached (see the `sudo` manpage for more info about this) +* An indicator when the current shell is inside the Vim editor +* Battery charging status (depends on the [../../plugins/available/battery.plugin.bash](battery plugin)) +* SCM Repository status (e.g. Git, SVN) +* The current Python environment (Virtualenv, venv, and Conda are supported) in use +* The current Ruby environment (rvm and rbenv are supported) in use +* Last command exit code (only shown when the exit code is greater than 0) + +## Configuration + +This theme is pretty configurable, all the configuration is done by setting environment variables. + +### User Information + +By default, the username and hostname are shown on the right hand side, but you can change this behavior by setting the value of the following variable: + + POWERLINE_PROMPT_USER_INFO_MODE="sudo" + +For now, the only supported value is `sudo`, which hides the username and hostname, and shows an indicator when `sudo` has the credentials cached. Other values have no effect at this time. + +### Clock Format + +By default, the current time is shown on the right hand side, you can change the format using the following variable: + + THEME_CLOCK_FORMAT="%H:%M:%S" + +The time/date is printed by the `date` command, so refer to its man page to change the format. + +### Segment Order + +The contents of both prompt sides can be "reordered", all the "segments" (every piece of information) can take any place. The currently available segments are: + +* battery +* clock +* cwd +* in_vim +* python_venv +* ruby +* scm +* user_info + +Two variables can be defined to set the order of the prompt segments: + + POWERLINE_LEFT_PROMPT="scm python_venv ruby cwd" + POWERLINE_RIGHT_PROMPT="in_vim clock battery user_info" + +The example values above are the current default values, but if you want to remove anything from the prompt, simply remove the "string" that represents the segment from the corresponding variable. diff --git a/themes/powerline-r/powerline-r.base.bash b/themes/powerline-r/powerline-r.base.bash new file mode 100644 index 00000000..28c07a62 --- /dev/null +++ b/themes/powerline-r/powerline-r.base.bash @@ -0,0 +1,62 @@ +. "$BASH_IT/themes/powerline/powerline.base.bash" + +function __powerline_last_status_prompt { + [[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}" +} + +function __powerline_right_segment { + local OLD_IFS="${IFS}"; IFS="|" + local params=( $1 ) + IFS="${OLD_IFS}" + local separator_char="${POWERLINE_RIGHT_SEPARATOR}" + local padding=2 + local separator_color="" + + if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then + separator_color="$(set_color ${params[1]} -)" + else + separator_color="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})" + (( padding += 1 )) + fi + RIGHT_PROMPT+="${separator_color}${separator_char}${normal}$(set_color - ${params[1]}) ${params[0]} ${normal}$(set_color - ${COLOR})${normal}" + RIGHT_PROMPT_LENGTH=$(( ${#params[0]} + RIGHT_PROMPT_LENGTH + padding )) + LAST_SEGMENT_COLOR="${params[1]}" + (( SEGMENTS_AT_RIGHT += 1 )) +} + +function __powerline_prompt_command { + local last_status="$?" ## always the first + local separator_char="${POWERLINE_LEFT_SEPARATOR}" + local move_cursor_rightmost='\033[500C' + + LEFT_PROMPT="" + RIGHT_PROMPT="" + RIGHT_PROMPT_LENGTH=0 + SEGMENTS_AT_LEFT=0 + SEGMENTS_AT_RIGHT=0 + LAST_SEGMENT_COLOR="" + + ## left prompt ## + for segment in $POWERLINE_LEFT_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" + done + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}" + + ## right prompt ## + if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then + LEFT_PROMPT+="${move_cursor_rightmost}" + for segment in $POWERLINE_RIGHT_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_right_segment "${info}" + done + LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D" + fi + + PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${PROMPT_CHAR} " + + ## cleanup ## + unset LAST_SEGMENT_COLOR \ + LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \ + SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT +} diff --git a/themes/powerline-r/powerline-r.theme.bash b/themes/powerline-r/powerline-r.theme.bash new file mode 100644 index 00000000..f034235d --- /dev/null +++ b/themes/powerline-r/powerline-r.theme.bash @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# My powerline-r theme + +. "$BASH_IT/custom/powerline-r/powerline-r.base.bash" + +THEME_PROMPT_SEPARATOR="" + +SHELL_SSH_CHAR=" " +SHELL_THEME_PROMPT_COLOR=39 +SHELL_SSH_THEME_PROMPT_COLOR=214 + +SCM_GIT_BEHIND_CHAR="↓" +SCM_GIT_AHEAD_CHAR="↑" +if [[ -z "$THEME_SCM_TAG_PREFIX" ]]; then +SCM_TAG_PREFIX="tag > " +else +SCM_TAG_PREFIX="$THEME_SCM_TAG_PREFIX" +fi +SCM_THEME_PROMPT_CLEAN="" +SCM_THEME_PROMPT_DIRTY="" +SCM_THEME_PROMPT_COLOR=237 +SCM_THEME_PROMPT_CLEAN_COLOR=230 +SCM_THEME_PROMPT_DIRTY_COLOR=226 +SCM_THEME_PROMPT_STAGED_COLOR=206 +SCM_THEME_PROMPT_UNTRACKED_COLOR=033 + +PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:="❯"} +POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""} +POWERLINE_RIGHT_SEPARATOR=${POWERLINE_RIGHT_SEPARATOR:=""} + +USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} +USER_INFO_THEME_PROMPT_COLOR=32 +USER_INFO_THEME_PROMPT_COLOR_SUDO=202 + +PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:="❲p❳ "} +CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} +PYTHON_VENV_THEME_PROMPT_COLOR=35 + +SCM_NONE_CHAR="" +SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "} +SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} + +RVM_THEME_PROMPT_PREFIX="" +RVM_THEME_PROMPT_SUFFIX="" +RBENV_THEME_PROMPT_PREFIX="" +RBENV_THEME_PROMPT_SUFFIX="" +RUBY_THEME_PROMPT_COLOR=161 +RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} + +CWD_THEME_PROMPT_COLOR=240 + +LAST_STATUS_THEME_PROMPT_COLOR=196 + +CLOCK_THEME_PROMPT_COLOR=240 + +BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"} +BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 +BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 +BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 + +THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} + +IN_VIM_THEME_PROMPT_COLOR=245 +IN_VIM_THEME_PROMPT_TEXT="vim" + +POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby cwd"} +POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"} + +safe_append_prompt_command __powerline_prompt_command