Merge pull request #1 from Bash-it/master

Update from upstream
pull/487/head
Miguel Morales 2015-05-12 11:27:37 -05:00
commit 2b99e43d81
24 changed files with 326 additions and 73 deletions

View File

@ -0,0 +1,18 @@
cite 'about-alias'
about-alias 'pbcopy and pbpaste shortcuts to linux'
case $OSTYPE in
linux*)
XCLIP=$(command -v xclip)
[[ $XCLIP ]] && alias pbcopy="$XCLIP -selection clipboard" && alias pbpaste="$XCLIP -selection clipboard -o"
;;
esac
# to use it just install xclip on your distribution and it would work like:
# $ echo "hello" | pbcopy
# $ pbpaste
# hello
# very useful for things like:
# cat ~/.ssh/id_rsa.pub | pbcopy
# have fun!

View File

@ -0,0 +1,3 @@
# https://github.com/nvbn/thefuck
alias fuck='eval $(thefuck $(fc -ln -1))'
alias please='fuck'

View File

@ -3,7 +3,7 @@
cite 'about-alias'
about-alias 'homebrew abbreviations'
alias bup='brew update && brew upgrade'
alias bup='brew update && brew upgrade --all'
alias bout='brew outdated'
alias bin='brew install'
alias brm='brew uninstall'

View File

@ -71,7 +71,7 @@ done
unset config_file
if [[ $PROMPT ]]; then
export PS1=$PROMPT
export PS1="\["$PROMPT"\]"
fi
# Adding Support for other OSes
@ -81,7 +81,7 @@ PREVIEW="less"
# Load all the Jekyll stuff
if [ -e $HOME/.jekyllconfig ]
if [ -e "$HOME/.jekyllconfig" ]
then
. $HOME/.jekyllconfig
. "$HOME/.jekyllconfig"
fi

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Bash completion support for the 'dirs' plugin (commands G, R).
_dirs-complete() {
local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}"
# parse all defined shortcuts from ~/.dirs
if [ -r "$HOME/.dirs" ]; then
COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) )
fi
return 0
}
complete -o default -o nospace -F _dirs-complete G R

View File

@ -16,11 +16,17 @@
#
# To use these routines:
#
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
# 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
# 2) Add the following line to your .bashrc/.zshrc:
# source ~/.git-completion.sh
# source ~/.git-completion.bash
# 3) Consider changing your PS1 to also show the current branch,
# see git-prompt.sh for details.
#
# If you use complex aliases of form '!f() { ... }; f', you can use the null
# command ':' as the first command in the function body to declare the desired
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
case "$COMP_WORDBREAKS" in
*:*) : great ;;
@ -180,7 +186,7 @@ fi
__gitcompappend ()
{
local i=${#COMPREPLY[@]}
local x i=${#COMPREPLY[@]}
for x in $1; do
if [[ "$x" == "$3"* ]]; then
COMPREPLY[i++]="$2$x$4"
@ -275,16 +281,12 @@ __gitcomp_file ()
# argument, and using the options specified in the second argument.
__git_ls_files_helper ()
{
(
test -n "${CDPATH+set}" && unset CDPATH
cd "$1"
if [ "$2" == "--committable" ]; then
git diff-index --name-only --relative HEAD
else
# NOTE: $2 is not quoted in order to support multiple options
git ls-files --exclude-standard $2
fi
) 2>/dev/null
if [ "$2" == "--committable" ]; then
git -C "$1" diff-index --name-only --relative HEAD
else
# NOTE: $2 is not quoted in order to support multiple options
git -C "$1" ls-files --exclude-standard $2
fi 2>/dev/null
}
@ -382,7 +384,8 @@ __git_refs ()
;;
*)
echo "HEAD"
git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
git for-each-ref --format="%(refname:short)" -- \
"refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
;;
esac
}
@ -408,12 +411,9 @@ __git_refs_remotes ()
__git_remotes ()
{
local i IFS=$'\n' d="$(__gitdir)"
local d="$(__gitdir)"
test -d "$d/remotes" && ls -1 "$d/remotes"
for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
i="${i#remote.}"
echo "${i/.url*/}"
done
git --git-dir="$d" remote
}
__git_list_merge_strategies ()
@ -516,7 +516,7 @@ __git_complete_index_file ()
;;
esac
__gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
__gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
}
__git_complete_file ()
@ -781,6 +781,10 @@ __git_aliased_command ()
-*) : option ;;
*=*) : setting env ;;
git) : git itself ;;
\(\)) : skip parens of shell function definition ;;
{) : skip start of shell helper function ;;
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*)
echo "$word"
return
@ -973,7 +977,7 @@ _git_branch ()
case "$cur" in
--set-upstream-to=*)
__gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
__gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
;;
--*)
__gitcomp "
@ -1041,7 +1045,7 @@ _git_checkout ()
_git_cherry ()
{
__gitcomp "$(__git_refs)"
__gitcomp_nl "$(__git_refs)"
}
_git_cherry_pick ()
@ -1165,8 +1169,8 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
--full-index --binary --abbrev --diff-filter=
--find-copies-harder
--text --ignore-space-at-eol --ignore-space-change
--ignore-all-space --exit-code --quiet --ext-diff
--no-ext-diff
--ignore-all-space --ignore-blank-lines --exit-code
--quiet --ext-diff --no-ext-diff
--no-prefix --src-prefix= --dst-prefix=
--inter-hunk-context=
--patience --histogram --minimal
@ -1197,7 +1201,7 @@ _git_diff ()
}
__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
"
_git_difftool ()
@ -1298,7 +1302,7 @@ _git_gitk ()
}
__git_match_ctag() {
awk "/^${1////\\/}/ { print \$1 }" "$2"
awk "/^${1//\//\\/}/ { print \$1 }" "$2"
}
_git_grep ()
@ -1418,7 +1422,7 @@ __git_log_gitk_options="
# Options that go well for log and shortlog (not gitk)
__git_log_shortlog_options="
--author= --committer= --grep=
--all-match
--all-match --invert-grep
"
__git_log_pretty_formats="oneline short medium full fuller email raw format:"
@ -1457,6 +1461,7 @@ _git_log ()
--abbrev-commit --abbrev=
--relative-date --date=
--pretty= --format= --oneline
--show-signature
--cherry-pick
--graph
--decorate --decorate=
@ -1611,12 +1616,33 @@ _git_pull ()
__git_push_recurse_submodules="check on-demand"
__git_complete_force_with_lease ()
{
local cur_=$1
case "$cur_" in
--*=)
;;
*:*)
__gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
;;
*)
__gitcomp_nl "$(__git_refs)" "" "$cur_"
;;
esac
}
_git_push ()
{
case "$prev" in
--repo)
__gitcomp_nl "$(__git_remotes)"
return
;;
--recurse-submodules)
__gitcomp "$__git_push_recurse_submodules"
return
;;
esac
case "$cur" in
--repo=*)
@ -1627,11 +1653,16 @@ _git_push ()
__gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
return
;;
--force-with-lease=*)
__git_complete_force_with_lease "${cur##--force-with-lease=}"
return
;;
--*)
__gitcomp "
--all --mirror --tags --dry-run --force
--force-with-lease --verbose --receive-pack= --repo=
--set-upstream --recurse-submodules=
--all --mirror --tags --dry-run --force --verbose
--quiet --prune --delete --follow-tags
--receive-pack= --repo= --set-upstream
--force-with-lease --force-with-lease= --recurse-submodules=
"
return
;;
@ -1659,6 +1690,7 @@ _git_rebase ()
--committer-date-is-author-date --ignore-date
--ignore-whitespace --whitespace=
--autosquash --fork-point --no-fork-point
--autostash
"
return
@ -1841,6 +1873,10 @@ _git_config ()
__gitcomp "$__git_send_email_suppresscc_options"
return
;;
sendemail.transferencoding)
__gitcomp "7bit 8bit quoted-printable base64"
return
;;
--get|--get-all|--unset|--unset-all)
__gitcomp_nl "$(__git_config_get_set_variables)"
return
@ -1975,6 +2011,7 @@ _git_config ()
color.status.changed
color.status.header
color.status.nobranch
color.status.unmerged
color.status.untracked
color.status.updated
color.ui
@ -2149,6 +2186,7 @@ _git_config ()
pull.octopus
pull.twohead
push.default
push.followTags
rebase.autosquash
rebase.stat
receive.autogc
@ -2308,6 +2346,7 @@ _git_show ()
;;
--*)
__gitcomp "--pretty= --format= --abbrev-commit --oneline
--show-signature
$__git_diff_common_options
"
return
@ -2513,6 +2552,16 @@ _git_tag ()
__gitcomp_nl "$(__git_refs)"
;;
esac
case "$cur" in
--*)
__gitcomp "
--list --delete --verify --annotate --message --file
--sign --cleanup --local-user --force --column --sort
--contains --points-at
"
;;
esac
}
_git_whatchanged ()

View File

@ -13,14 +13,14 @@ _sshcomplete() {
# parse all defined hosts from .ssh/config
if [ -r $HOME/.ssh/config ]; then
COMPREPLY=($(compgen -W "$(grep ^Host $HOME/.ssh/config | awk '{print $2}' )" ${OPTIONS}) )
if [ -r "$HOME/.ssh/config" ]; then
COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{print $2}' )" ${OPTIONS}) )
fi
# parse all hosts found in .ssh/known_hosts
if [ -r $HOME/.ssh/known_hosts ]; then
if grep -v -q -e '^ ssh-rsa' $HOME/.ssh/known_hosts ; then
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( awk '{print $1}' $HOME/.ssh/known_hosts | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) )
if [ -r "$HOME/.ssh/known_hosts" ]; then
if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts" ; then
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( awk '{print $1}' "$HOME/.ssh/known_hosts" | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) )
fi
fi

View File

@ -11,7 +11,7 @@ _todo()
mv prepend prep pri p replace report"
# Add custom commands from add-ons, if installed.
COMMANDS="$COMMANDS $('ls' ${TODO_ACTIONS_DIR:-$HOME/.todo.actions.d}/ 2>/dev/null)"
COMMANDS="$COMMANDS $('ls' ${TODO_ACTIONS_DIR:-"$HOME/.todo.actions.d"}/ 2>/dev/null)"
OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x"

View File

@ -65,13 +65,18 @@ _vagrant() {
then
case "$prev" in
"init")
local box_list=$(find $HOME/.vagrant.d/boxes -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
"up")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -d $vagrant_state_file ]]
then
vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
fi
local up_commands="--no-provision"
COMPREPLY=($(compgen -W "${up_commands}" -- ${cur}))
COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur}))
return 0
;;
"ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config")
@ -113,10 +118,16 @@ _vagrant() {
then
action="${COMP_WORDS[COMP_CWORD-2]}"
case "$action" in
"up")
if [ "$prev" == "--no-provision" ]; then
COMPREPLY=($(compgen -W "${vm_list}" -- ${cur}))
return 0
fi
;;
"box")
case "$prev" in
"remove"|"repackage")
local box_list=$(find $HOME/.vagrant.d/boxes -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
@ -134,4 +145,3 @@ _vagrant() {
fi
}
complete -F _vagrant vagrant

View File

@ -10,11 +10,33 @@ case $OSTYPE in
;;
esac
test -w $HOME/$CONFIG_FILE &&
cp $HOME/$CONFIG_FILE $HOME/$CONFIG_FILE.bak &&
BACKUP_FILE=$CONFIG_FILE.bak
if [ -e "$HOME/$BACKUP_FILE" ]; then
echo "Backup file already exists. Make sure to backup your .bashrc before running this installation." >&2
while true
do
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
case $RESP in
[yY])
break
;;
[nN]|"")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
exit 1
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
fi
test -w "$HOME/$CONFIG_FILE" &&
cp -a "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo "Your original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak"
cp $HOME/.bash_it/template/bash_profile.template.bash $HOME/$CONFIG_FILE
cp "$HOME/.bash_it/template/bash_profile.template.bash" "$HOME/$CONFIG_FILE"
echo "Copied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it"
@ -39,16 +61,15 @@ function load_some() {
for path in `ls $BASH_IT/${file_type}/available/[^_]*`
do
file_name=$(basename "$path")
while true; do
read -s -n 1 -p "Would you like to enable the ${file_name%%.*} $file_type? [y/N] " RESP
while true
do
read -e -n 1 -p "Would you like to enable the ${file_name%%.*} $file_type? [y/N] " RESP
case $RESP in
[yY])
echo "Y"
ln -s "../available/${file_name}" "$BASH_IT/$file_type/enabled"
break
;;
[nN]|"")
echo "N"
break
;;
*)
@ -71,19 +92,19 @@ then
else
while true
do
read -p "Do you use Jekyll? (If you don't know what Jekyll is, answer 'n') [Y/N] " RESP
read -e -n 1 -p "Do you use Jekyll? (If you don't know what Jekyll is, answer 'n') [y/N] " RESP
case $RESP in
[yY])
cp $HOME/.bash_it/template/jekyllconfig.template.bash $HOME/.jekyllconfig
cp "$HOME/.bash_it/template/jekyllconfig.template.bash" "$HOME/.jekyllconfig"
echo "Copied the template .jekyllconfig into your home directory. Edit this file to customize bash-it for using the Jekyll plugins"
break
;;
[nN])
[nN]|"")
break
;;
*)
echo "Please enter Y or N"
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
@ -112,4 +133,5 @@ else
esac
done
done
echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
fi

View File

@ -0,0 +1,72 @@
cite about-plugin
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
__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
else
__awskeys_help
fi
}
function __awskeys_help {
echo -e "Usage: awskeys [COMMAND] [profile]\n"
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"
}
function __awskeys_get {
local ln=$(grep -n "\[ *$1 *\]" ~/.aws/credentials | cut -d ":" -f 1)
if [[ -n "${ln}" ]]; then
tail -n +${ln} ~/.aws/credentials | egrep -m 2 "aws_access_key_id|aws_secret_access_key"
fi
}
function __awskeys_list {
local credentials_list="$(egrep '^\[ *[a-zA-Z0-0_-]+ *\]$' ~/.aws/credentials)"
if [[ -n $"{credentials_list}" ]]; then
echo -e "Available credentials profiles:\n"
for cred in ${credentials_list}; do
echo " $(echo ${cred} | tr -d "[]")"
done
echo
else
echo "No profiles found in credentials file"
fi
}
function __awskeys_show {
local p_keys="$(__awskeys_get $1)"
if [[ -n "${p_keys}" ]]; then
echo "${p_keys}"
else
echo "Profile $1 not found in credentials file"
fi
}
function __awskeys_export {
local p_keys="$(__awskeys_get $1)"
if [[ -n "${p_keys}" ]]; then
eval $(echo "${p_keys}" | tr -d " " | sed -r -e "s/(.+=)(.+)/export \U\1\E\2/")
export AWS_DEFAULT_PROFILE="$1"
else
echo "Profile $1 not found in credentials file"
fi
}

View File

@ -80,8 +80,8 @@ function mkcd ()
example '$ mkcd foo'
example '$ mkcd /tmp/img/photos/large'
group 'base'
mkdir -p "$*"
cd "$*"
mkdir -p -- "$*"
cd -- "$*"
}
function lsgrep ()
@ -213,5 +213,5 @@ function buf ()
group 'base'
local filename=$1
local filetime=$(date +%Y%m%d_%H%M%S)
cp "${filename}" "${filename}_${filetime}"
cp -a "${filename}" "${filename}_${filetime}"
}

View File

@ -66,7 +66,7 @@ battery_percentage(){
# http://hints.macworld.com/article.php?story=20100130123935998
#local IOREG_OUTPUT_10_6=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}')
#local IOREG_OUTPUT_10_5=$(ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}')
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
case $IOREG_OUTPUT in
100*)
echo '99'

View File

@ -8,7 +8,7 @@
cite about-plugin
about-plugin 'node version manager, as a bash function'
export NVM_DIR=$HOME/.nvm
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
mkdir $NVM_DIR

View File

@ -1,7 +1,7 @@
cite about-plugin
about-plugin 'load pipsi, if you are using it'
if [[ -f $HOME/.local/bin/pipsi ]]
if [[ -f "$HOME/.local/bin/pipsi" ]]
then
export PATH=~/.local/bin:$PATH
fi

View File

@ -3,7 +3,7 @@
cite about-plugin
about-plugin 'load rvm, if you are using it'
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Check to make sure that RVM is actually loaded before adding
# the customizations to it.

View File

@ -1,4 +1,4 @@
cite about-plugin
about-plugin 'sources tmuxinator script if available'
[[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && . $HOME/.tmuxinator/scripts/tmuxinator
[[ -s "$HOME/.tmuxinator/scripts/tmuxinator" ]] && . "$HOME/.tmuxinator/scripts/tmuxinator"

View File

@ -536,7 +536,7 @@ shift $(($OPTIND - 1))
# defaults if not yet defined
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-$HOME/.todo/config}
TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-"$HOME/.todo/config"}
TODOTXT_FORCE=${TODOTXT_FORCE:-0}
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}

View File

@ -11,7 +11,7 @@ autoenv_init()
typeset target home _file
typeset -a _files
target=$1
home="$(dirname $HOME)"
home="$(dirname "$HOME")"
_files=( $(
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Path to the bash it configuration
export BASH_IT=$HOME/.bash_it
export BASH_IT="$HOME/.bash_it"
# Lock and Load a custom theme file
# location /.bash_it/themes/

View File

@ -16,8 +16,8 @@ load ../../plugins/available/base.plugin
}
@test 'plugins base: myip()' {
if [[ ! $CI ]]; then
skip 'myip is slow - run only on CI'
if [[ ! $SLOW_TESTS ]]; then
skip 'myip is slow - run only with SLOW_TESTS=true'
fi
run myip
@ -27,10 +27,30 @@ load ../../plugins/available/base.plugin
}
@test 'plugins base: pickfrom()' {
mkdir -p $BASH_IT_ROOT
stub_file="${BASH_IT_ROOT}/stub_file"
printf "l1\nl2\nl3" > $stub_file
run pickfrom $stub_file
assert_success
[[ $output == l? ]]
}
@test 'plugins base: mkcd()' {
cd "${BASH_IT_ROOT}"
run mkcd -dir_with_dash
assert_success
}
@test 'plugins base: lsgrep()' {
for i in 1 2 3; do mkdir -p "${BASH_IT_TEST_DIR}/${i}"; done
cd $BASH_IT_TEST_DIR
run lsgrep 2
assert_success
assert_equal 2 $output
}
@test 'plugins base: buf()' {
declare -r file="${BASH_IT_ROOT}/file"
touch $file
run buf $file
[[ -e ${file}_$(date +%Y%m%d_%H%M%S) ]]
}

View File

@ -13,8 +13,12 @@ if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then
export BASH_IT=$BASH_IT_TEST_DIR
fi
setup() {
mkdir -p -- "${BASH_IT_ROOT}"
}
teardown() {
rm -rf "$BASH_IT_TEST_DIR"
rm -rf "${BASH_IT_TEST_DIR}"
}
assert() {

View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
function get_hour_color {
hour_color=$red
min=$(date +%M)
if [ "$min" -lt "15" ]; then
hour_color=$white
elif [ "$min" -lt "30" ]; then
hour_color=$green
elif [ "$min" -lt "45" ]; then
hour_color=$yellow
else
hour_color=$red
fi
echo "$hour_color"
}
function prompt_command() {
PS1="\n$(get_hour_color)$(date +%H) ${purple}\h ${reset_color}in ${prompt_color}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
PROMPT_COMMAND=prompt_command;

View File

@ -5,6 +5,7 @@ THEME_PROMPT_LEFT_SEPARATOR=""
SHELL_SSH_CHAR=${SHELL_SSH_CHAR:=" "}
SHELL_THEME_PROMPT_COLOR=32
SHELL_THEME_PROMPT_COLOR_SUDO=202
VIRTUALENV_CHAR=${POWERLINE_VIRTUALENV_CHAR:="p "}
CONDA_VIRTUALENV_CHAR=${POWERLINE_CONDA_VIRTUALENV_CHAR:="c "}
@ -53,6 +54,11 @@ 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
SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR_SUDO}
fi
SEGMENT_AT_RIGHT=0
if [[ -n "${SSH_CLIENT}" ]]; then
SHELL_PROMPT="${SHELL_SSH_CHAR}${USER}@${HOSTNAME}"
@ -60,8 +66,8 @@ function powerline_shell_prompt {
SHELL_PROMPT="${USER}"
fi
RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 2 ))
SHELL_PROMPT="$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}"
LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
SHELL_PROMPT="$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}"
LAST_THEME_COLOR=${SHELL_PROMPT_COLOR}
(( SEGMENT_AT_RIGHT += 1 ))
}