Skip to content

Commit

Permalink
Results from linting
Browse files Browse the repository at this point in the history
  • Loading branch information
buhl committed Jan 9, 2021
1 parent f3e7ad1 commit dfbb4d2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 62 deletions.
3 changes: 3 additions & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
9 changes: 4 additions & 5 deletions plugins/available/cmd-returned-notify.plugin.bash
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
35 changes: 17 additions & 18 deletions plugins/available/xterm.plugin.bash
Original file line number Diff line number Diff line change
@@ -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
78 changes: 39 additions & 39 deletions themes/command_duration.theme.bash
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

0 comments on commit dfbb4d2

Please sign in to comment.