From dfbb4d2f751208fc104586a96e591a299a46506e Mon Sep 17 00:00:00 2001 From: buhl <221842+buhl@users.noreply.github.com> Date: Sat, 9 Jan 2021 19:04:47 +0100 Subject: [PATCH] Results from linting --- clean_files.txt | 3 + .../available/cmd-returned-notify.plugin.bash | 9 +-- plugins/available/xterm.plugin.bash | 35 ++++----- themes/command_duration.theme.bash | 78 +++++++++---------- 4 files changed, 63 insertions(+), 62 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2120e418a0..6d979052cc 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -29,10 +29,13 @@ themes/agnoster themes/90210 themes/powerline themes/barbuk +themes/command_duration.theme.bash # plugins # plugins/available/basher.plugin.bash +plugins/available/cmd-returned-notify.plugin.bash +plugins/available/xterm.plugin.bash # completions # diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index 17f6a40791..1df30c5f47 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -1,15 +1,14 @@ cite about-plugin about-plugin 'Alert (BEL) when process ends after a threshold of seconds' - precmd_return_notification() { - LAST_COMMAND_DURATION=$(expr $(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)}) - [[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a" - LAST_COMMAND_TIME= + LAST_COMMAND_DURATION=$(( $(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)})) + [[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a" + LAST_COMMAND_TIME= } preexec_return_notification() { - [ -z "${LAST_COMMAND_TIME}" ] && LAST_COMMAND_TIME=$(date +%s) + [ -z "${LAST_COMMAND_TIME}" ] && LAST_COMMAND_TIME=$(date +%s) } precmd_functions+=(precmd_return_notification) diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index fce78e4980..718e6e0c0f 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -1,33 +1,32 @@ cite about-plugin about-plugin 'automatically set your xterm title with host and location info' - -_short-dirname () { - local dir_name=`dirs +0` - [ "$SHORT_TERM_LINE" = true ] && [ ${#dir_name} -gt 8 ] && echo ${dir_name##*/} || echo $dir_name +_short-dirname() { + local dir_name=$(dirs +0) + [ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}" } -_short-command () { - local input_command="$@" - [ "$SHORT_TERM_LINE" = true ] && [ ${#input_command} -gt 8 ] && echo ${input_command%% *} || echo $input_command +_short-command() { + local input_command="$*" + [ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}" } -set_xterm_title () { - local title="$1" - echo -ne "\033]0;$title\007" +set_xterm_title() { + local title="$1" + echo -ne "\033]0;$title\007" } -precmd_xterm_title () { - set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `_short-dirname` $PROMPTCHAR" +precmd_xterm_title() { + set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPTCHAR" } -preexec_xterm_title () { - set_xterm_title "`_short-command $1` {`_short-dirname`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" +preexec_xterm_title() { + set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" } case "$TERM" in - xterm*|rxvt*) - precmd_functions+=(precmd_xterm_title) - preexec_functions+=(preexec_xterm_title) - ;; + xterm* | rxvt*) + precmd_functions+=(precmd_xterm_title) + preexec_functions+=(preexec_xterm_title) + ;; esac diff --git a/themes/command_duration.theme.bash b/themes/command_duration.theme.bash index e0e836b3e9..b9f78d13c5 100644 --- a/themes/command_duration.theme.bash +++ b/themes/command_duration.theme.bash @@ -1,10 +1,10 @@ #!/usr/bin/env bash if [ -z "$BASH_IT_COMMAND_DURATION" ] || [ "$BASH_IT_COMMAND_DURATION" != true ]; then - _command_duration() { - echo -n - } - return + _command_duration() { + echo -n + } + return fi # Define tmp dir and file @@ -17,53 +17,53 @@ COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'} trap _command_duration_delete_temp_file EXIT HUP INT TERM _command_duration_delete_temp_file() { - if [[ -f "$COMMAND_DURATION_FILE" ]]; then - rm -f "$COMMAND_DURATION_FILE" - fi + if [[ -f "$COMMAND_DURATION_FILE" ]]; then + rm -f "$COMMAND_DURATION_FILE" + fi } _command_duration_pre_exec() { - date +%s.%1N > "$COMMAND_DURATION_FILE" + date +%s.%1N > "$COMMAND_DURATION_FILE" } _command_duration() { - local command_duration command_start current_time - local minutes seconds deciseconds - local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds - current_time=$(date +%s.%1N) + local command_duration command_start current_time + local minutes seconds deciseconds + local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds + current_time=$(date +%s.%1N) - if [[ -f "$COMMAND_DURATION_FILE" ]]; then - command_start=$(< "$COMMAND_DURATION_FILE") - command_start_sseconds=${command_start%.*} - current_time_seconds=${current_time%.*} + if [[ -f "$COMMAND_DURATION_FILE" ]]; then + command_start=$(< "$COMMAND_DURATION_FILE") + command_start_sseconds=${command_start%.*} + current_time_seconds=${current_time%.*} - command_start_deciseconds=$((10#${command_start#*.})) - current_time_deciseconds=$((10#${current_time#*.})) + command_start_deciseconds=$((10#${command_start#*.})) + current_time_deciseconds=$((10#${current_time#*.})) - # seconds - command_duration=$(( current_time_seconds - command_start_sseconds )) + # seconds + command_duration=$((current_time_seconds - command_start_sseconds)) - if (( current_time_deciseconds >= command_start_deciseconds )); then - deciseconds=$(( (current_time_deciseconds - command_start_deciseconds) )) - else - ((command_duration-=1)) - deciseconds=$(( 10 - ( (command_start_deciseconds - current_time_deciseconds) ) )) - fi - command rm "$COMMAND_DURATION_FILE" - else - command_duration=0 - fi + if ((current_time_deciseconds >= command_start_deciseconds)); then + deciseconds=$(((current_time_deciseconds - command_start_deciseconds))) + else + ((command_duration -= 1)) + deciseconds=$((10 - ((command_start_deciseconds - current_time_deciseconds)))) + fi + command rm "$COMMAND_DURATION_FILE" + else + command_duration=0 + fi - if (( command_duration > 0 )); then - minutes=$(( command_duration / 60 )) - seconds=$(( command_duration % 60 )) - fi + if ((command_duration > 0)); then + minutes=$((command_duration / 60)) + seconds=$((command_duration % 60)) + fi - if (( minutes > 0 )); then - printf "%s%s%dm %ds" "$COMMAND_DURATION_ICON" "$COMMAND_DURATION_COLOR" "$minutes" "$seconds" - elif (( seconds >= COMMAND_DURATION_MIN_SECONDS )); then - printf "%s%s%d.%01ds" "$COMMAND_DURATION_ICON" "$COMMAND_DURATION_COLOR" "$seconds" "$deciseconds" - fi + if ((minutes > 0)); then + printf "%s%s%dm %ds" "$COMMAND_DURATION_ICON" "$COMMAND_DURATION_COLOR" "$minutes" "$seconds" + elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then + printf "%s%s%d.%01ds" "$COMMAND_DURATION_ICON" "$COMMAND_DURATION_COLOR" "$seconds" "$deciseconds" + fi } preexec_functions+=(_command_duration_pre_exec)