From 0ddf972d992d627c938601ffadc98bfce2819fe1 Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 7 Apr 2015 15:50:52 -0500 Subject: [PATCH 01/21] Add aliases to copy to and paste from clipboard on the terminal for linux environments; analogous to pbpaste and pbcopy on Mac --- aliases/available/clipboard.aliases.bash | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 aliases/available/clipboard.aliases.bash diff --git a/aliases/available/clipboard.aliases.bash b/aliases/available/clipboard.aliases.bash new file mode 100644 index 00000000..a9d8c151 --- /dev/null +++ b/aliases/available/clipboard.aliases.bash @@ -0,0 +1,20 @@ +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" + ;; + darwin*) + ;; +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! From a9159268519d86199183dbbb61aedb5f58e5bb6b Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 7 Apr 2015 15:52:30 -0500 Subject: [PATCH 02/21] Emperor theme; features time on the prompt with different colors for each quater of the hour --- themes/emperor/emperor.theme.bash | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 themes/emperor/emperor.theme.bash diff --git a/themes/emperor/emperor.theme.bash b/themes/emperor/emperor.theme.bash new file mode 100644 index 00000000..8d9313b2 --- /dev/null +++ b/themes/emperor/emperor.theme.bash @@ -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; From 29c8e572c1de13580160aaeb42495ad97a0284aa Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Thu, 9 Apr 2015 10:34:04 -0500 Subject: [PATCH 03/21] Remove darwin from the case --- aliases/available/clipboard.aliases.bash | 2 -- 1 file changed, 2 deletions(-) diff --git a/aliases/available/clipboard.aliases.bash b/aliases/available/clipboard.aliases.bash index a9d8c151..21b770a6 100644 --- a/aliases/available/clipboard.aliases.bash +++ b/aliases/available/clipboard.aliases.bash @@ -6,8 +6,6 @@ case $OSTYPE in XCLIP=$(command -v xclip) [[ $XCLIP ]] && alias pbcopy="$XCLIP -selection clipboard" && alias pbpaste="$XCLIP -selection clipboard -o" ;; - darwin*) - ;; esac # to use it just install xclip on your distribution and it would work like: From c81971d1d8838178155cf02aa0a26b157016a742 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 11 Apr 2015 13:45:58 -0700 Subject: [PATCH 04/21] preserve attributes of $CONFIG_FILE on backup --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 26c62c24..7c3ff111 100755 --- a/install.sh +++ b/install.sh @@ -11,7 +11,7 @@ case $OSTYPE in esac test -w $HOME/$CONFIG_FILE && - cp $HOME/$CONFIG_FILE $HOME/$CONFIG_FILE.bak && + 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 From f4205609862258e875859707129d7c46add88ee7 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 11 Apr 2015 13:50:39 -0700 Subject: [PATCH 05/21] make buf() to respect file attributes on file backup --- plugins/available/base.plugin.bash | 2 +- test/plugins/base.plugin.bats | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 8c8a2c50..837d7536 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -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}" } diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 9bc9f0e6..1d940984 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -34,3 +34,11 @@ load ../../plugins/available/base.plugin assert_success [[ $output == l? ]] } + +@test 'plugins base: buf()' { + mkdir -p $BASH_IT_ROOT + declare -r file="${BASH_IT_ROOT}/file" + touch $file + run buf $file + [[ -e ${file}_$(date +%Y%m%d_%H%M%S) ]] +} From 409e5529704fa9e3216580455f8760ade9043c6c Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Thu, 16 Apr 2015 10:39:12 +0200 Subject: [PATCH 06/21] Added completion for dirs plugin --- completion/available/dirs.completion.bash | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 completion/available/dirs.completion.bash diff --git a/completion/available/dirs.completion.bash b/completion/available/dirs.completion.bash new file mode 100644 index 00000000..67888ebe --- /dev/null +++ b/completion/available/dirs.completion.bash @@ -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 From 2160c70c15bdf86a36729f2f079ebad047a4ea19 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 17 Apr 2015 14:22:13 +0200 Subject: [PATCH 07/21] Added sudo indicator If the user is currently in a valid sudo session (sudo currently does not require a password), then the username part of the right prompt will use a different color (orange). This gives an indication to the user that sudo commands will not require a password at the moment. One example for this might be that the user is reminded to run a `sudo -k` to terminate the current sudo session before stepping away from the screen. --- .../powerline-multiline/powerline-multiline.theme.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index b8fa67ba..232a2a8e 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -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 )) } From 7166fbf12a46e7a0b7b1ae5c26f825f73f4abebb Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 21 Apr 2015 11:23:04 +0300 Subject: [PATCH 08/21] Updated vagrant bash completion. --- completion/available/vagrant.completion.bash | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/completion/available/vagrant.completion.bash b/completion/available/vagrant.completion.bash index 6ed16230..c5d52283 100644 --- a/completion/available/vagrant.completion.bash +++ b/completion/available/vagrant.completion.bash @@ -70,8 +70,13 @@ _vagrant() { 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,6 +118,12 @@ _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") @@ -134,4 +145,3 @@ _vagrant() { fi } complete -F _vagrant vagrant - From bd6b4d8a28c66a5d6aebb60227a8da9e53b33b5e Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 21 Apr 2015 11:29:45 +0300 Subject: [PATCH 09/21] Updated git completion. Fixes #299. --- completion/available/git.completion.bash | 109 ++++++++++++++++------- 1 file changed, 79 insertions(+), 30 deletions(-) diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index cfede1fc..5944c824 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -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 () From fb2134364e0647c71a1e8c271fe0573d2e4a3918 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Tue, 21 Apr 2015 21:09:51 -0700 Subject: [PATCH 10/21] skip myip() function test - it is not determenistic, probably because of the network latency --- test/plugins/base.plugin.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 1d940984..2216040b 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -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 From 5a5f3d99d2c82c3e2bc0089368537b6cd37ec2ef Mon Sep 17 00:00:00 2001 From: shaief Date: Wed, 22 Apr 2015 11:17:08 +0300 Subject: [PATCH 11/21] Add confirmation before deleting .bak file. Add message when installation script ends. --- install.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/install.sh b/install.sh index 7c3ff111..1599eb50 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,30 @@ case $OSTYPE in ;; esac +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 + read -s -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file [y/N] " RESP + while true + do + case $RESP in + [yY]) + break + ;; + [nN]|"") + echo "Installation aborted. Please come back soon!" + exit 1 + ;; + *) + echo -e "\033[91mUnknown choice. Please choose y or N.\033[m" + read -s -n 1 -p " " RESP + continue + ;; + 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" @@ -112,4 +136,5 @@ else esac done done +echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m" fi From a2bddd5c7534ccb7faf9985159dae86c39be83b2 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Sun, 26 Apr 2015 12:00:17 +0200 Subject: [PATCH 12/21] Updated install script All of the install questions are now using the same syntax and semantics for read/echo/case. --- install.sh | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 1599eb50..1a97b9f3 100755 --- a/install.sh +++ b/install.sh @@ -14,21 +14,19 @@ 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 - read -s -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file [y/N] " RESP 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 "Installation aborted. Please come back soon!" + echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" exit 1 ;; *) - echo -e "\033[91mUnknown choice. Please choose y or N.\033[m" - read -s -n 1 -p " " RESP - continue + echo -e "\033[91mPlease choose y or n.\033[m" ;; esac done @@ -63,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 ;; *) @@ -95,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 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 From f4a77e8e18e8a9ab9cf53e1262465fc1519d19b8 Mon Sep 17 00:00:00 2001 From: Ruben Nijveld Date: Mon, 27 Apr 2015 00:32:53 +0200 Subject: [PATCH 13/21] Homebrew upgrade command wants --all flag Homebrew currently gives a warning about how this flag will be required in the future, as merged in Homebrew/homebrew#38572 --- aliases/available/homebrew.aliases.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aliases/available/homebrew.aliases.bash b/aliases/available/homebrew.aliases.bash index ebb9e015..3dce114b 100644 --- a/aliases/available/homebrew.aliases.bash +++ b/aliases/available/homebrew.aliases.bash @@ -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' From 1da435f9a6de98b5daf9ba5823be7288a350c758 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Sun, 26 Apr 2015 20:44:09 +0200 Subject: [PATCH 14/21] Added aliases for nvbn/thefuck https://github.com/nvbn/thefuck --- aliases/available/fuck.aliases.bash | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 aliases/available/fuck.aliases.bash diff --git a/aliases/available/fuck.aliases.bash b/aliases/available/fuck.aliases.bash new file mode 100644 index 00000000..54648931 --- /dev/null +++ b/aliases/available/fuck.aliases.bash @@ -0,0 +1,3 @@ +# https://github.com/nvbn/thefuck +alias fuck='eval $(thefuck $(fc -ln -1))' +alias please='fuck' From 4510c9ee63703670bbd98fb95efdd8d1f3fbb6e0 Mon Sep 17 00:00:00 2001 From: Benjamin Brombach Date: Tue, 21 Apr 2015 16:17:38 +0200 Subject: [PATCH 15/21] fixes #343 by surrounding $HOME (which can have spaces) with quotations marks --- bash_it.sh | 4 ++-- completion/available/dirs.completion.bash | 2 +- completion/available/ssh.completion.bash | 10 +++++----- completion/available/todo.completion.bash | 2 +- completion/available/vagrant.completion.bash | 4 ++-- install.sh | 10 +++++----- plugins/available/nvm.plugin.bash | 2 +- plugins/available/pipsi.plugin.bash | 2 +- plugins/available/rvm.plugin.bash | 2 +- plugins/available/tmuxinator.plugin.bash | 2 +- plugins/available/todo/todo.sh | 2 +- plugins/available/z_autoenv.plugin.bash | 2 +- template/bash_profile.template.bash | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 8557a236..0416306f 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -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 diff --git a/completion/available/dirs.completion.bash b/completion/available/dirs.completion.bash index 67888ebe..ba18db32 100644 --- a/completion/available/dirs.completion.bash +++ b/completion/available/dirs.completion.bash @@ -5,7 +5,7 @@ _dirs-complete() { local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" # parse all defined shortcuts from ~/.dirs - if [ -r $HOME/.dirs ]; then + if [ -r "$HOME/.dirs" ]; then COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) ) fi diff --git a/completion/available/ssh.completion.bash b/completion/available/ssh.completion.bash index fd5c6cd5..396be8f2 100644 --- a/completion/available/ssh.completion.bash +++ b/completion/available/ssh.completion.bash @@ -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 diff --git a/completion/available/todo.completion.bash b/completion/available/todo.completion.bash index 00493dbc..da365ea6 100644 --- a/completion/available/todo.completion.bash +++ b/completion/available/todo.completion.bash @@ -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" diff --git a/completion/available/vagrant.completion.bash b/completion/available/vagrant.completion.bash index c5d52283..e0abb7af 100644 --- a/completion/available/vagrant.completion.bash +++ b/completion/available/vagrant.completion.bash @@ -65,7 +65,7 @@ _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 ;; @@ -127,7 +127,7 @@ _vagrant() { "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 ;; diff --git a/install.sh b/install.sh index 1a97b9f3..bbd01411 100755 --- a/install.sh +++ b/install.sh @@ -12,7 +12,7 @@ esac BACKUP_FILE=$CONFIG_FILE.bak -if [ -e $HOME/$BACKUP_FILE ]; then +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 @@ -32,11 +32,11 @@ if [ -e $HOME/$BACKUP_FILE ]; then done fi -test -w $HOME/$CONFIG_FILE && - cp -a $HOME/$CONFIG_FILE $HOME/$CONFIG_FILE.bak && +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" @@ -95,7 +95,7 @@ else 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 ;; diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 2e607d66..632de967 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -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 diff --git a/plugins/available/pipsi.plugin.bash b/plugins/available/pipsi.plugin.bash index 3a645782..305e83cc 100644 --- a/plugins/available/pipsi.plugin.bash +++ b/plugins/available/pipsi.plugin.bash @@ -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 diff --git a/plugins/available/rvm.plugin.bash b/plugins/available/rvm.plugin.bash index 6acad079..ac2598ef 100644 --- a/plugins/available/rvm.plugin.bash +++ b/plugins/available/rvm.plugin.bash @@ -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. diff --git a/plugins/available/tmuxinator.plugin.bash b/plugins/available/tmuxinator.plugin.bash index a0114352..e0dc28f0 100644 --- a/plugins/available/tmuxinator.plugin.bash +++ b/plugins/available/tmuxinator.plugin.bash @@ -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" diff --git a/plugins/available/todo/todo.sh b/plugins/available/todo/todo.sh index 59f88a91..c2e149f0 100755 --- a/plugins/available/todo/todo.sh +++ b/plugins/available/todo/todo.sh @@ -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} diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index dd1aec14..553a7ba3 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -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" ]] diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 35104ece..9fda847e 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -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/ From 067f851d795b5db889af7060fb894373b699c60a Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 3 May 2015 17:34:23 -0700 Subject: [PATCH 16/21] [tests] added test for plugins base lsgrep() --- test/plugins/base.plugin.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 2216040b..70950296 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -35,6 +35,14 @@ load ../../plugins/available/base.plugin [[ $output == l? ]] } +@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()' { mkdir -p $BASH_IT_ROOT declare -r file="${BASH_IT_ROOT}/file" From f1de827622484d43fb571d209fdefab6fc6bd00e Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 3 May 2015 18:08:12 -0700 Subject: [PATCH 17/21] [tests] added test for base plugin mkcd(); make mkcd() safe for directory names starting with a dash --- plugins/available/base.plugin.bash | 4 ++-- test/plugins/base.plugin.bats | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 837d7536..aa35a708 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -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 () diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 70950296..07b6afc7 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -35,6 +35,12 @@ load ../../plugins/available/base.plugin [[ $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 From 34670ea02114e8827f06eaa55d600e29bbcd45e9 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 3 May 2015 18:10:15 -0700 Subject: [PATCH 18/21] [tests] make setup function to create test dir per test --- test/plugins/base.plugin.bats | 2 -- test/test_helper.bash | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 07b6afc7..3b21ca7f 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -27,7 +27,6 @@ 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 @@ -50,7 +49,6 @@ load ../../plugins/available/base.plugin } @test 'plugins base: buf()' { - mkdir -p $BASH_IT_ROOT declare -r file="${BASH_IT_ROOT}/file" touch $file run buf $file diff --git a/test/test_helper.bash b/test/test_helper.bash index 850b6161..71b3a16c 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -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() { From 2d13b3294a0d50ea8f035a533b12590ebcc24aff Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 4 May 2015 20:09:44 +0200 Subject: [PATCH 19/21] Fixed conversion when the battery percentage is in the single digits. The previous version was printing an error when the battery percentage was in the single digits, e.g. "7.04%". The code cuts returns the first two digits, which in the case of "7.04%" are "7.". Any code that tries to use that, e.g. the powerline-multiline theme will fail with an error. This change corrects that by zero padding single digits, i.e. "07.04%" instead of "7.04%". --- plugins/available/battery.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index c1b2dbd5..75741c4a 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -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' From a8124a02e8f793d5512261cf244c26ad1f57ecfc Mon Sep 17 00:00:00 2001 From: Fahad Hossain Date: Wed, 6 May 2015 22:37:24 +0600 Subject: [PATCH 20/21] Fix unicode line wrap problem (issue #409) Fix unicode line wrap issue mentioned in #409 Nota bene, This fixed the problem for me on Fedora 21 and Ubuntu 15.04 Needs to be tested on other systems --- bash_it.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_it.sh b/bash_it.sh index 0416306f..21445034 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -71,7 +71,7 @@ done unset config_file if [[ $PROMPT ]]; then - export PS1=$PROMPT + export PS1="\["$PROMPT"\]" fi # Adding Support for other OSes From 767a7a63ca6419730fd9004cbc4b45d6e8e9e9ac Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Sat, 9 May 2015 01:33:30 +0200 Subject: [PATCH 21/21] Added AWS plugin - awskeys, helper function for credentials profiles --- plugins/available/aws.plugin.bash | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/available/aws.plugin.bash diff --git a/plugins/available/aws.plugin.bash b/plugins/available/aws.plugin.bash new file mode 100644 index 00000000..68fc4907 --- /dev/null +++ b/plugins/available/aws.plugin.bash @@ -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 +} +