performance and ui improvements

- better alias recommendation UI.
- add function to randomly execute whatever function/alias is passed as
argument.
- the default jira check executed when opening a session will now only
  occurs 1/10 times.
This commit is contained in:
MorganGeek 2020-07-12 10:20:12 +02:00
parent 4002d62840
commit 336aaa2729
2 changed files with 20 additions and 8 deletions

View File

@ -113,11 +113,17 @@ function top_commands_full() {
history | \cat | awk '{$1=$1};1' | sed 's/^[0-9 TAB]*//g' | awk '{CMD[$0]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "%\t" a; }' | grep "$filter" | sort -nr | nl | head -n50 history | \cat | awk '{$1=$1};1' | sed 's/^[0-9 TAB]*//g' | awk '{CMD[$0]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "%\t" a; }' | grep "$filter" | sort -nr | nl | head -n50
} }
function suggest_aliases() { function suggest_aliases() {
header "alias recommendations"
while read -r line while read -r line
do do
local matching_aliases=$(ag "$line") local matching_aliases=$(ag "$line")
if [ ! -z "$matching_aliases" ]; then if [ ! -z "$matching_aliases" ]; then
echo "there is an alias for $line :\n$matching_aliases\n" success "there is an alias for $line :"
while read -r alias_line
do
arrow "$alias_line"
done < <(echo "$matching_aliases")
echo
fi fi
done < <(top_commands_full | awk '{ $1=""; $2=""; $3=""; print}' | awk 'NF' | awk '{$1=$1};1' | awk -v COUNT=1 'NF>COUNT' | head -20) done < <(top_commands_full | awk '{ $1=""; $2=""; $3=""; print}' | awk 'NF' | awk '{$1=$1};1' | awk -v COUNT=1 'NF>COUNT' | head -20)
} }
@ -478,3 +484,14 @@ function file_dups {
function foreach_run { function foreach_run {
find . -name "$1" -exec "$2" {} \; find . -name "$1" -exec "$2" {} \;
} }
# input should be something like : 1-10 to generate one number between 1 and 10
function chance {
[[ $(shuf -i "$1" -n 1) == 1 ]]
}
function runiflucky {
if chance "1-10"; then
if alias "$1" 2> /dev/null || (compgen -A function | grep "$1" && compgen -A function "$1" 1>/dev/null); then
eval "$1"
fi
fi
}

View File

@ -30,7 +30,6 @@ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs command_execution_tim
POWERLEVEL9K_SHOW_CHANGESET=true POWERLEVEL9K_SHOW_CHANGESET=true
POWERLEVEL9K_CHANGESET_HASH_LENGTH=8 POWERLEVEL9K_CHANGESET_HASH_LENGTH=8
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR='' POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=''
POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR='' POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR=''
@ -38,13 +37,11 @@ POWERLEVEL9K_TIME_FOREGROUND='245'
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='245' POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='245'
POWERLEVEL9K_STATUS_OK_FOREGROUND='green' POWERLEVEL9K_STATUS_OK_FOREGROUND='green'
POWERLEVEL9k_STATUS_ERROR_FOREGROUND='red' POWERLEVEL9k_STATUS_ERROR_FOREGROUND='red'
POWERLEVEL9k_STATUS_ERROR_FOREGROUND='red'
POWERLEVEL9K_TIME_BACKGROUND='clear' POWERLEVEL9K_TIME_BACKGROUND='clear'
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='clear' POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='clear'
POWERLEVEL9K_STATUS_OK_BACKGROUND='clear' POWERLEVEL9K_STATUS_OK_BACKGROUND='clear'
POWERLEVEL9K_STATUS_ERROR_BACKGROUND='clear' POWERLEVEL9K_STATUS_ERROR_BACKGROUND='clear'
POWERLEVEL9K_STATUS_ERROR_BACKGROUND='clear'
POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND='clear' POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND='clear'
# Set list of themes to pick from when loading at random # Set list of themes to pick from when loading at random
@ -151,8 +148,8 @@ eval "$(fasd --init auto)"
#cm apply #cm apply
# check if we have new jira issues # randomly check if we have new jira issues
istherenewissues runiflucky "istherenewissues"
case "$(uname -s)" in case "$(uname -s)" in
Darwin) Darwin)
@ -165,8 +162,6 @@ esac
export SDKMAN_DIR="$HOME/.sdkman" export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh" [[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
#sdk use java 8.0.202-zulu
case "$(uname -s)" in case "$(uname -s)" in
Darwin) Darwin)
ln -snf /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/bin/pip /usr/local/bin/pip3 ln -snf /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/bin/pip /usr/local/bin/pip3