Merge branch 'master' of https://github.com/Bash-it/bash-it
commit
2043ef36ee
|
|
@ -200,7 +200,7 @@ export BASH_IT_THEME="powerline-multiline"
|
|||
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`.
|
||||
You can easily preview the themes in your own shell using `BASH_PREVIEW=true bash-it 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).
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ alias bcin='brew cask install'
|
|||
alias bcrm='brew cask uninstall'
|
||||
alias bczp='brew cask zap'
|
||||
alias bccl='brew cask cleanup'
|
||||
alias bcsr='brew cask search'
|
||||
alias bcls='brew cask list'
|
||||
alias bcinf='brew cask info'
|
||||
alias bcdr='brew cask doctor'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# -binaryanomaly
|
||||
|
||||
cite 'about-alias'
|
||||
about-alias 'kubectl aliases'
|
||||
|
||||
# set apt aliases
|
||||
function _set_pkg_aliases()
|
||||
{
|
||||
if [ -x $(which kubectl) ]; then
|
||||
alias kc='kubectl'
|
||||
alias kcgp='kubectl get pods'
|
||||
alias kcgd='kubectl get deployments'
|
||||
alias kcgn='kubectl get nodes'
|
||||
alias kcdp='kubectl describe pod'
|
||||
alias kcdd='kubectl describe deployment'
|
||||
alias kcdn='kubectl describe node'
|
||||
alias kcgpan='kubectl get pods --all-namespaces'
|
||||
alias kcgdan='kubectl get deployments --all-namespaces'
|
||||
fi
|
||||
}
|
||||
|
||||
_set_pkg_aliases
|
||||
|
|
@ -3,9 +3,12 @@ about-alias 'maven abbreviations'
|
|||
|
||||
alias mci='mvn clean install'
|
||||
alias mi='mvn install'
|
||||
alias mcp='mvn clean package'
|
||||
alias mp='mvn package'
|
||||
alias mrprep='mvn release:prepare'
|
||||
alias mrperf='mvn release:perform'
|
||||
alias mrrb='mvn release:rollback'
|
||||
alias mdep='mvn dependency:tree'
|
||||
alias mpom='mvn help:effective-pom'
|
||||
alias mcisk='mci -Dmaven.test.skip=true'
|
||||
alias mcpsk='mcp -Dmaven.test.skip=true'
|
||||
|
|
|
|||
25
bash_it.sh
25
bash_it.sh
|
|
@ -4,18 +4,19 @@
|
|||
# Only set $BASH_IT if it's not already set
|
||||
if [ -z "$BASH_IT" ];
|
||||
then
|
||||
# Setting $BASH to maintain backwards compatibility
|
||||
# TODO: warn users that they should upgrade their .bash_profile
|
||||
export BASH_IT=$BASH
|
||||
export BASH="$(bash -c 'echo $BASH')"
|
||||
# Setting $BASH to maintain backwards compatibility
|
||||
# TODO: warn users that they should upgrade their .bash_profile
|
||||
export BASH_IT=$BASH
|
||||
BASH="$(bash -c 'echo $BASH')"
|
||||
export BASH
|
||||
fi
|
||||
|
||||
# For backwards compatibility, look in old BASH_THEME location
|
||||
if [ -z "$BASH_IT_THEME" ];
|
||||
then
|
||||
# TODO: warn users that they should upgrade their .bash_profile
|
||||
export BASH_IT_THEME="$BASH_THEME";
|
||||
unset $BASH_THEME;
|
||||
# TODO: warn users that they should upgrade their .bash_profile
|
||||
export BASH_IT_THEME="$BASH_THEME";
|
||||
unset BASH_THEME;
|
||||
fi
|
||||
|
||||
# Load composure first, so we support function metadata
|
||||
|
|
@ -30,9 +31,9 @@ LIB="${BASH_IT}/lib/*.bash"
|
|||
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
|
||||
for config_file in $LIB
|
||||
do
|
||||
if [ $config_file != $APPEARANCE_LIB ]; then
|
||||
if [ "$config_file" != "$APPEARANCE_LIB" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
source $config_file
|
||||
source "$config_file"
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ source "${BASH_IT}/themes/base.theme.bash"
|
|||
|
||||
# appearance (themes) now, after all dependencies
|
||||
# shellcheck source=./lib/appearance.bash
|
||||
source $APPEARANCE_LIB
|
||||
source "$APPEARANCE_LIB"
|
||||
|
||||
# Load custom aliases, completion, plugins
|
||||
for file_type in "aliases" "completion" "plugins"
|
||||
|
|
@ -75,13 +76,13 @@ for config_file in $CUSTOM
|
|||
do
|
||||
if [ -e "${config_file}" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
source $config_file
|
||||
source "$config_file"
|
||||
fi
|
||||
done
|
||||
|
||||
unset config_file
|
||||
if [[ $PROMPT ]]; then
|
||||
export PS1="\[""$PROMPT""\]"
|
||||
export PS1="\[""$PROMPT""\]"
|
||||
fi
|
||||
|
||||
# Adding Support for other OSes
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# minikube (Local Kubernetes) completion
|
||||
|
||||
if command -v minikube &>/dev/null
|
||||
then
|
||||
eval "$(minikube completion bash)"
|
||||
fi
|
||||
|
|
@ -27,10 +27,14 @@ _sdkman_complete()
|
|||
esac
|
||||
elif [ $COMP_CWORD -eq 3 ]; then
|
||||
case "${COMP_WORDS[COMP_CWORD-2]}" in
|
||||
"install" | "uninstall" | "rm" | "use" | "default" )
|
||||
"uninstall" | "rm" | "use" | "default" )
|
||||
_sdkman_candidate_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"install")
|
||||
_sdkman_candidate_not_installed_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
|
@ -51,6 +55,14 @@ _sdkman_candidate_versions(){
|
|||
|
||||
}
|
||||
|
||||
_sdkman_candidate_not_installed_versions(){
|
||||
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions $1)
|
||||
if [ "$SDKMAN_OFFLINE_MODE" = "false" ]; then
|
||||
CANDIDATE_ONLINE_VERSIONS="$(__sdkman_list_versions $1 | grep " " | grep "\." | cut -c 6-)"
|
||||
CANDIDATE_VERSIONS="$(echo $CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS | tr ' ' '\n' | sort | uniq -u) "
|
||||
fi
|
||||
}
|
||||
|
||||
__sdkman_cleanup_local_versions(){
|
||||
|
||||
__sdkman_build_version_csv $1 | tr ',' ' '
|
||||
|
|
|
|||
|
|
@ -11,11 +11,16 @@ _sshcomplete() {
|
|||
local OPTIONS=" -- ${CURRENT_PROMPT}"
|
||||
fi
|
||||
|
||||
|
||||
# parse all defined hosts from .ssh/config
|
||||
if [ -r "$HOME/.ssh/config" ]; then
|
||||
COMPREPLY=($(compgen -W "$(grep -i ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
|
||||
fi
|
||||
# parse all defined hosts from .ssh/config and files included there
|
||||
for fl in "$HOME/.ssh/config" \
|
||||
$(grep "^\s*Include" "$HOME/.ssh/config" |
|
||||
awk '{for (i=2; i<=NF; i++) print $i}' |
|
||||
sed "s|^~/|$HOME/|")
|
||||
do
|
||||
if [ -r "$fl" ]; then
|
||||
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$(grep -i ^Host "$fl" |grep -v '[*!]' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
|
||||
fi
|
||||
done
|
||||
|
||||
# parse all hosts found in .ssh/known_hosts
|
||||
if [ -r "$HOME/.ssh/known_hosts" ]; then
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ if [ $(uname) = "Darwin" ] && command -v brew &>/dev/null ; then
|
|||
. "$BREW_PREFIX"/etc/bash_completion
|
||||
fi
|
||||
|
||||
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
|
||||
if [ -f "$BREW_PREFIX"/share/bash-completion/bash_completion ]; then
|
||||
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
|
||||
if [ "${BASH_VERSINFO}" -ge 4 ] && [ -f "$BREW_PREFIX"/share/bash-completion/bash_completion ]; then
|
||||
. "$BREW_PREFIX"/share/bash-completion/bash_completion
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ function reload_plugins() {
|
|||
bash-it ()
|
||||
{
|
||||
about 'Bash-it help and maintenance'
|
||||
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload ] '
|
||||
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload ] '
|
||||
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
|
||||
param '3: specific component [optional]'
|
||||
example '$ bash-it show plugins'
|
||||
|
|
@ -79,28 +79,28 @@ bash-it ()
|
|||
shift
|
||||
typeset func
|
||||
case $verb in
|
||||
show)
|
||||
func=_bash-it-$component;;
|
||||
enable)
|
||||
func=_enable-$component;;
|
||||
disable)
|
||||
func=_disable-$component;;
|
||||
help)
|
||||
func=_help-$component;;
|
||||
search)
|
||||
_bash-it-search $component "$@"
|
||||
return;;
|
||||
update)
|
||||
func=_bash-it_update;;
|
||||
migrate)
|
||||
func=_bash-it-migrate;;
|
||||
version)
|
||||
func=_bash-it-version;;
|
||||
reload)
|
||||
func=_bash-it-reload;;
|
||||
*)
|
||||
reference bash-it
|
||||
return;;
|
||||
show)
|
||||
func=_bash-it-$component;;
|
||||
enable)
|
||||
func=_enable-$component;;
|
||||
disable)
|
||||
func=_disable-$component;;
|
||||
help)
|
||||
func=_help-$component;;
|
||||
search)
|
||||
_bash-it-search $component "$@"
|
||||
return;;
|
||||
update)
|
||||
func=_bash-it_update;;
|
||||
migrate)
|
||||
func=_bash-it-migrate;;
|
||||
version)
|
||||
func=_bash-it-version;;
|
||||
reload)
|
||||
func=_bash-it-reload;;
|
||||
*)
|
||||
reference bash-it
|
||||
return;;
|
||||
esac
|
||||
|
||||
# pluralize component if necessary
|
||||
|
|
@ -187,7 +187,7 @@ _bash-it_update() {
|
|||
_bash-it-migrate
|
||||
echo ""
|
||||
echo "All done, enjoy!"
|
||||
reload
|
||||
bash-it reload
|
||||
else
|
||||
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ about-plugin 'load fzf, if you are using it'
|
|||
|
||||
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
|
||||
|
||||
if [ -z ${FZF_DEFAULT_COMMAND+x} ]; then
|
||||
command -v fd &> /dev/null && export FZF_DEFAULT_COMMAND='fd --type f'
|
||||
fi
|
||||
|
||||
fe() {
|
||||
about "Open the selected file in the default editor"
|
||||
group "fzf"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
cite about-plugin
|
||||
about-plugin 'Maven jgitflow build helpers'
|
||||
|
||||
function hotfix-start {
|
||||
about 'helper function for starting a new hotfix'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS}
|
||||
}
|
||||
|
||||
function hotfix-finish {
|
||||
about 'helper function for finishing a hotfix'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags
|
||||
}
|
||||
|
||||
function feature-start {
|
||||
about 'helper function for starting a new feature'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS}
|
||||
}
|
||||
|
||||
function feature-finish {
|
||||
about 'helper function for finishing a feature'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:feature-finish ${JGITFLOW_MVN_ARGUMENTS}
|
||||
echo -e '\033[32m----------------------------------------------------------------\033[0m'
|
||||
echo -e '\033[32m===== REMEMBER TO CREATE A NEW RELEASE TO DEPLOY THIS FEATURE ====\033[0m'
|
||||
echo -e '\033[32m----------------------------------------------------------------\033[0m'
|
||||
}
|
||||
|
||||
function release-start {
|
||||
about 'helper function for starting a new release'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:release-start ${JGITFLOW_MVN_ARGUMENTS}
|
||||
}
|
||||
|
||||
function release-finish {
|
||||
about 'helper function for finishing a release'
|
||||
group 'jgitflow'
|
||||
|
||||
mvn jgitflow:release-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
cite about-plugin
|
||||
about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump)'
|
||||
|
||||
__init_jump() {
|
||||
command -v jump &> /dev/null || return
|
||||
eval "$(jump shell --bind=z)"
|
||||
}
|
||||
|
||||
__init_jump
|
||||
|
|
@ -5,7 +5,7 @@ about-plugin 'osx-specific functions'
|
|||
if [ $(uname) = "Darwin" ]; then
|
||||
if type update_terminal_cwd > /dev/null 2>&1 ; then
|
||||
if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then
|
||||
PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd"
|
||||
PROMPT_COMMAND="${PROMPT_COMMAND%;};update_terminal_cwd"
|
||||
declared="$(declare -p PROMPT_COMMAND)"
|
||||
[[ "$declared" =~ \ -[aAilrtu]*x[aAilrtu]*\ ]] 2>/dev/null
|
||||
[[ $? -eq 0 ]] && export PROMPT_COMMAND
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'enables powerline daemon'
|
||||
|
||||
command -v powerline-daemon &>/dev/null || return
|
||||
powerline-daemon -q
|
||||
|
||||
#the following should not be executed if bashit powerline themes in use
|
||||
case "$BASH_IT_THEME" in
|
||||
*powerline*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
POWERLINE_BASH_CONTINUATION=1
|
||||
POWERLINE_BASH_SELECT=1
|
||||
bashPowerlineInit=$(python -c \
|
||||
"import os; \
|
||||
import powerline;\
|
||||
print(os.path.join(os.path.dirname(\
|
||||
powerline.__file__),\
|
||||
'bindings', \
|
||||
'bash', \
|
||||
'powerline.sh'))")
|
||||
[ -e $bashPowerlineInit ] || return
|
||||
. $bashPowerlineInit
|
||||
|
|
@ -347,7 +347,7 @@ function condaenv_prompt {
|
|||
}
|
||||
|
||||
function py_interp_prompt {
|
||||
py_version=$(python --version 2>&1 | awk '{print "py-"$2;}') || return
|
||||
py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return
|
||||
echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
|
|
@ -393,6 +393,7 @@ function user_host_prompt {
|
|||
|
||||
# backwards-compatibility
|
||||
function git_prompt_info {
|
||||
_git-hide-status && return
|
||||
git_prompt_vars
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
# Single line PS1 theme w/realtime history among windows
|
||||
|
||||
|
||||
Minimal theme overrides from bash_it base theming
|
||||
|
||||
|
||||
## `user@host:path[virt-env][scm] $`
|
||||
Breakdown of the segments:
|
||||
|
||||
- **user@host:path** - *convienient for LAN based `ssh` and `scp` tasks*
|
||||
- [**virtualenv**] - *only appears when activated*
|
||||
- [**scm**] - *only appears when activated*
|
||||
- **marker** - *$ or # depending on current user*
|
||||
|
||||
### Examples
|
||||
|
||||
```bash
|
||||
user@example.lan:~ $ cd /tmp/foo/bar/baz
|
||||
user@example.lan:/tmp/foo/bar/baz $ cd $HOME/workspace
|
||||
user@example.lan:~/workspace $ cd sampleRepo/
|
||||
user@example.lan:~/workspace/sampleRepo [± |master ↑1 ↓3 {1} S:2 ?:1 ✗|] $
|
||||
```
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
SCM_THEME_PROMPT_PREFIX=${SCM_THEME_PROMPT_SUFFIX}
|
||||
SCM_THEME_PROMPT_DIRTY="${bold_red} ✗${normal}"
|
||||
SCM_THEME_PROMPT_CLEAN="${bold_green} ✓${normal}"
|
||||
SCM_GIT_CHAR="${green}±${normal}"
|
||||
|
||||
scm_prompt() {
|
||||
CHAR=$(scm_char)
|
||||
if [ $CHAR = $SCM_NONE_CHAR ]
|
||||
then
|
||||
return
|
||||
else
|
||||
echo " [$(scm_char)$(scm_prompt_info)]"
|
||||
fi
|
||||
}
|
||||
|
||||
mark_prompt() {
|
||||
echo "${green}\$${normal}"
|
||||
}
|
||||
|
||||
user_host_path_prompt() {
|
||||
ps_user="${green}\u${normal}";
|
||||
ps_host="${blue}\H${normal}";
|
||||
ps_path="${yellow}\w${normal}";
|
||||
echo "$ps_user@$ps_host:$ps_path"
|
||||
}
|
||||
|
||||
prompt() {
|
||||
PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) "
|
||||
}
|
||||
|
||||
share_history() {
|
||||
history -a
|
||||
history -c
|
||||
history -r
|
||||
}
|
||||
|
||||
safe_append_prompt_command share_history
|
||||
safe_append_prompt_command prompt
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function set_prompt_symbol () {
|
||||
if test $1 -eq 0 ; then
|
||||
PROMPT_SYMBOL=">_"
|
||||
else
|
||||
PROMPT_SYMBOL="${orange}>_${normal}"
|
||||
fi
|
||||
}
|
||||
function prompt_command() {
|
||||
set_prompt_symbol $?
|
||||
if test -z "$VIRTUAL_ENV" ; then
|
||||
PYTHON_VIRTUALENV=""
|
||||
else
|
||||
PYTHON_VIRTUALENV="${bold_yellow}[`basename \"$VIRTUAL_ENV\"`]"
|
||||
fi
|
||||
|
||||
PS1="${bold_orange}${PYTHON_VIRTUALENV}${reset_color}${bold_green}[\w]${bold_blue}\[$(scm_prompt_info)\]${normal} \n${PROMPT_SYMBOL} "
|
||||
}
|
||||
|
||||
# scm themeing
|
||||
SCM_THEME_PROMPT_DIRTY=" ✗"
|
||||
SCM_THEME_PROMPT_CLEAN=" ✓"
|
||||
SCM_THEME_PROMPT_PREFIX="["
|
||||
SCM_THEME_PROMPT_SUFFIX="]"
|
||||
|
||||
safe_append_prompt_command prompt_command
|
||||
|
|
@ -25,7 +25,7 @@ RVM_THEME_PROMPT_SUFFIX=""
|
|||
RBENV_THEME_PROMPT_PREFIX=""
|
||||
RBENV_THEME_PROMPT_SUFFIX=""
|
||||
RUBY_THEME_PROMPT_COLOR=161
|
||||
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="ⓔ "}
|
||||
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="💎 "}
|
||||
|
||||
CWD_THEME_PROMPT_COLOR=240
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env bash
|
||||
# Power-Turk theme for bash-it
|
||||
# Author (C) 2015 Ahmed Seref Guneysu
|
||||
|
||||
THEME_PROMPT_SEPARATOR=""
|
||||
|
||||
SHELL_SSH_CHAR=" "
|
||||
SHELL_THEME_PROMPT_COLOR=2
|
||||
SHELL_SSH_THEME_PROMPT_COLOR=208
|
||||
|
||||
VIRTUALENV_CHAR="ⓔ "
|
||||
VIRTUALENV_THEME_PROMPT_COLOR=35
|
||||
|
||||
SCM_NONE_CHAR=""
|
||||
|
||||
SCM_GIT_CHAR=" " # " "
|
||||
|
||||
SCM_THEME_PROMPT_CLEAN=""
|
||||
SCM_THEME_PROMPT_DIRTY=""
|
||||
|
||||
SCM_THEME_PROMPT_COLOR=16
|
||||
SCM_THEME_PROMPT_CLEAN_COLOR=231
|
||||
SCM_THEME_PROMPT_DIRTY_COLOR=196
|
||||
SCM_THEME_PROMPT_STAGED_COLOR=220
|
||||
SCM_THEME_PROMPT_UNSTAGED_COLOR=166
|
||||
|
||||
CWD_THEME_PROMPT_COLOR=240
|
||||
|
||||
LAST_STATUS_THEME_PROMPT_COLOR=52
|
||||
|
||||
_collapsed_wd() {
|
||||
# echo -e "\u2771\u276d\u276f"
|
||||
echo $(pwd | perl -pe "
|
||||
BEGIN {
|
||||
binmode STDIN, ':encoding(UTF-8)';
|
||||
binmode STDOUT, ':encoding(UTF-8)';
|
||||
}; s|^$HOME|<HOME>|g; s|/([^/])[^/]*(?=/)|/\$1|g") | \
|
||||
sed -re "s/\// /g"
|
||||
}
|
||||
|
||||
_swd(){
|
||||
# Adapted from http://stackoverflow.com/a/2951707/1766716
|
||||
begin="" # The unshortened beginning of the path.
|
||||
shortbegin="" # The shortened beginning of the path.
|
||||
current="" # The section of the path we're currently working on.
|
||||
end="${2:-$(pwd)}/" # The unmodified rest of the path.
|
||||
|
||||
if [[ "$end" =~ "$HOME" ]]; then
|
||||
INHOME=1
|
||||
end="${end#$HOME}" #strip /home/username from start of string
|
||||
begin="$HOME" #start expansion from the right spot
|
||||
else
|
||||
INHOME=0
|
||||
fi
|
||||
|
||||
end="${end#/}" # Strip the first /
|
||||
shortenedpath="$end" # The whole path, to check the length.
|
||||
maxlength="${1:-0}"
|
||||
|
||||
shopt -q nullglob && NGV="-s" || NGV="-u" # Store the value for later.
|
||||
shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/...
|
||||
|
||||
while [[ "$end" ]] && (( ${#shortenedpath} > maxlength ))
|
||||
do
|
||||
current="${end%%/*}" # everything before the first /
|
||||
end="${end#*/}" # everything after the first /
|
||||
|
||||
shortcur="$current"
|
||||
shortcurstar="$current" # No star if we don't shorten it.
|
||||
|
||||
for ((i=${#current}-2; i>=0; i--)); do
|
||||
subcurrent="${current:0:i}"
|
||||
matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent.
|
||||
(( ${#matching[*]} != 1 )) && break # Stop shortening if more than one file matches.
|
||||
shortcur="$subcurrent"
|
||||
shortcurstar="$subcurrent*"
|
||||
done
|
||||
|
||||
#advance
|
||||
begin="$begin/$current"
|
||||
shortbegin="$shortbegin/$shortcurstar"
|
||||
shortenedpath="$shortbegin/$end"
|
||||
done
|
||||
|
||||
shortenedpath="${shortenedpath%/}" # strip trailing /
|
||||
shortenedpath="${shortenedpath#/}" # strip leading /
|
||||
|
||||
# Replaces slashes with except first occurence.
|
||||
if [ $INHOME -eq 1 ]; then
|
||||
echo "~/$shortenedpath" | sed "s/\///2g" # make sure it starts with ~/
|
||||
else
|
||||
echo "/$shortenedpath" | sed "s/\///2g" # Make sure it starts with /
|
||||
fi
|
||||
|
||||
shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function.
|
||||
|
||||
}
|
||||
function set_rgb_color {
|
||||
if [[ "${1}" != "-" ]]; then
|
||||
fg="38;5;${1}"
|
||||
fi
|
||||
if [[ "${2}" != "-" ]]; then
|
||||
bg="48;5;${2}"
|
||||
[[ -n "${fg}" ]] && bg=";${bg}"
|
||||
fi
|
||||
echo -e "\[\033[${fg}${bg}m\]"
|
||||
}
|
||||
|
||||
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}) ${normal}"
|
||||
LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
|
||||
fi
|
||||
}
|
||||
|
||||
function powerline_virtualenv_prompt {
|
||||
local environ=""
|
||||
|
||||
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
|
||||
environ="conda: $CONDA_DEFAULT_ENV"
|
||||
elif [[ -n "$VIRTUAL_ENV" ]]; then
|
||||
environ=$(basename "$VIRTUAL_ENV")
|
||||
fi
|
||||
|
||||
if [[ -n "$environ" ]]; then
|
||||
VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}"
|
||||
LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR}
|
||||
else
|
||||
VIRTUALENV_PROMPT=""
|
||||
fi
|
||||
}
|
||||
|
||||
function powerline_scm_prompt {
|
||||
scm_prompt_vars
|
||||
|
||||
if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
|
||||
if [[ "${SCM_DIRTY}" -eq 3 ]]; then
|
||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||
elif [[ "${SCM_DIRTY}" -eq 2 ]]; then
|
||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||
elif [[ "${SCM_DIRTY}" -eq 1 ]]; then
|
||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||
else
|
||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||
fi
|
||||
if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then
|
||||
SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
|
||||
fi
|
||||
SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}"
|
||||
LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR}
|
||||
else
|
||||
SCM_PROMPT=""
|
||||
fi
|
||||
}
|
||||
|
||||
function powerline_cwd_prompt {
|
||||
CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}$(set_rgb_color 0 ${CWD_THEME_PROMPT_COLOR}) $(_swd)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
|
||||
LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR}
|
||||
}
|
||||
|
||||
function powerline_last_status_prompt {
|
||||
if [[ "$1" -eq 0 ]]; then
|
||||
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
||||
else
|
||||
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
||||
fi
|
||||
}
|
||||
|
||||
function powerline_prompt_command() {
|
||||
local LAST_STATUS="$?"
|
||||
|
||||
powerline_shell_prompt
|
||||
powerline_virtualenv_prompt
|
||||
powerline_scm_prompt
|
||||
powerline_cwd_prompt
|
||||
powerline_last_status_prompt LAST_STATUS
|
||||
|
||||
PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} "
|
||||
}
|
||||
|
||||
PROMPT_COMMAND=powerline_prompt_command
|
||||
|
||||
|
|
@ -57,7 +57,12 @@ chroot(){
|
|||
|
||||
# show virtualenvwrapper
|
||||
my_ve(){
|
||||
if [ -n "$VIRTUAL_ENV" ]
|
||||
|
||||
if [ -n "$CONDA_DEFAULT_ENV" ]
|
||||
then
|
||||
my_ps_ve="${bold_purple}${CONDA_DEFAULT_ENV}${normal}";
|
||||
echo "($my_ps_ve)";
|
||||
elif [ -n "$VIRTUAL_ENV" ]
|
||||
then
|
||||
my_ps_ve="${bold_purple}$ve${normal}";
|
||||
echo "($my_ps_ve)";
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ esac
|
|||
BACKUP_FILE=$CONFIG_FILE.bak
|
||||
|
||||
if [ ! -e "$HOME/$BACKUP_FILE" ]; then
|
||||
echo -e "\033[0;33mBackup file "$HOME/$BACKUP_FILE" not found.\033[0m" >&2
|
||||
echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2
|
||||
|
||||
test -w "$HOME/$CONFIG_FILE" &&
|
||||
mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" &&
|
||||
|
|
|
|||
Loading…
Reference in New Issue