From f1822f9467ca597bc254a8349eed147c1b2581a8 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 10:06:10 +0200 Subject: [PATCH 1/3] lint cleanup for shfmt --- clean_files.txt | 1 + docs/themes-list/inretio.rst | 1 - plugins/available/browser.plugin.bash | 81 ++++++++++++++------------- themes/inretio/inretio.theme.bash | 52 ++++++++--------- themes/lambda/lambda.theme.bash | 46 +++++++-------- 5 files changed, 93 insertions(+), 88 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e8dff795bf..cf8d8bcb72 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/base.plugin.bash plugins/available/basher.plugin.bash plugins/available/battery.plugin.bash plugins/available/blesh.plugin.bash +plugins/available/browser.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/colors.plugin.bash plugins/available/direnv.plugin.bash diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst index 0e424a99f8..d37287d07c 100644 --- a/docs/themes-list/inretio.rst +++ b/docs/themes-list/inretio.rst @@ -29,4 +29,3 @@ In Python virtual environment: ┌──[2024-03-20 12:07:32] 🐧 gytis 💻 gytis-legion 🐍 3.12.2 on [general] 📂 general └> ls bin include lib lib64 pyvenv.cfg share - diff --git a/plugins/available/browser.plugin.bash b/plugins/available/browser.plugin.bash index f7d820aa07..b65d92ca76 100644 --- a/plugins/available/browser.plugin.bash +++ b/plugins/available/browser.plugin.bash @@ -1,39 +1,40 @@ +# shellcheck shell=bash # based on https://gist.github.com/318247 cite about-plugin about-plugin 'render commandline output in your browser' +# shellcheck disable=SC2120 function browser() { - about 'pipe html to a browser' - example '$ echo "

hi mom!

" | browser' - example '$ ron -5 man/rip.5.ron | browser' - group 'browser' + about 'pipe html to a browser' + example '$ echo "

hi mom!

" | browser' + example '$ ron -5 man/rip.5.ron | browser' + group 'browser' - if [ -t 0 ]; then - if [ -n "$1" ]; then - open $1 - else - reference browser - fi + if [ -t 0 ]; then + if [ -n "$1" ]; then + open "$1" + else + reference browser + fi - else - f="/tmp/browser.$RANDOM.html" - cat /dev/stdin > $f - open $f - fi + else + f="/tmp/browser.$RANDOM.html" + cat /dev/stdin > $f + open $f + fi } - function wmate() { - about 'pipe hot spicy interwebs into textmate and cleanup!' - example '$ wmate google.com' - group 'browser' - - if [ -t 0 ]; then - if [ -n "$1" ]; then - wget -qO- $1 | /usr/bin/mate + about 'pipe hot spicy interwebs into textmate and cleanup!' + example '$ wmate google.com' + group 'browser' -TIDY=`/usr/bin/osascript << EOT + if [ -t 0 ]; then + if [ -n "$1" ]; then + wget -qO- "$1" | /usr/bin/mate + TIDY=$( + /usr/bin/osascript << EOT tell application "TextMate" activate end tell @@ -53,24 +54,26 @@ tell application "System Events" end tell end tell end tell -EOT` +EOT + ) + export TIDY - else - reference wmate - fi - fi + else + reference wmate + fi + fi } function raw() { - about 'write wget into a temp file and pump it into your browser' - example '$ raw google.com' - group 'browser' + about 'write wget into a temp file and pump it into your browser' + example '$ raw google.com' + group 'browser' - if [ -t 0 ]; then - if [ -n "$1" ]; then - wget -qO- $1 | browser - else - reference raw - fi - fi + if [ -t 0 ]; then + if [ -n "$1" ]; then + wget -qO- "$1" | browser + else + reference raw + fi + fi } diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash index 58ac36ddfb..1db6c6d1f4 100644 --- a/themes/inretio/inretio.theme.bash +++ b/themes/inretio/inretio.theme.bash @@ -16,11 +16,11 @@ VIRTUALENV_THEME_PROMPT_SUFFIX="" # SCM prompts SCM_NONE_CHAR="" SCM_GIT_CHAR="[±] " -SCM_GIT_BEHIND_CHAR="${red}↓${normal}" -SCM_GIT_AHEAD_CHAR="${bold_green}↑${normal}" +SCM_GIT_BEHIND_CHAR="${red?}↓${normal?}" +SCM_GIT_AHEAD_CHAR="${bold_green?}↑${normal?}" SCM_GIT_UNTRACKED_CHAR="⌀" -SCM_GIT_UNSTAGED_CHAR="${bold_yellow}•${normal}" -SCM_GIT_STAGED_CHAR="${bold_green}+${normal}" +SCM_GIT_UNSTAGED_CHAR="${bold_yellow?}•${normal?}" +SCM_GIT_STAGED_CHAR="${bold_green?}+${normal?}" SCM_THEME_PROMPT_DIRTY="" SCM_THEME_PROMPT_CLEAN="" @@ -28,8 +28,8 @@ SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" # Git status prompts -GIT_THEME_PROMPT_DIRTY=" ${red}✗${normal}" -GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" +GIT_THEME_PROMPT_DIRTY=" ${red?}✗${normal?}" +GIT_THEME_PROMPT_CLEAN=" ${bold_green?}✓${normal?}" GIT_THEME_PROMPT_PREFIX="" GIT_THEME_PROMPT_SUFFIX="" @@ -48,32 +48,32 @@ icon_end="└> " # Display virtual environment info function _virtualenv_prompt { - VIRTUALENV_DETAILS="" - VIRTUALENV_CHAR="" - - # $VIRTUAL_ENV is set and is non-zero length - if [[ -n "$VIRTUAL_ENV" ]]; then - # Check if Python 3 exists - if command -v python3 >/dev/null 2>&1; then - VIRTUALENV_DETAILS="$($VIRTUAL_ENV/bin/python --version | sed 's,Python ,,') on [$(basename $VIRTUAL_ENV)]" - VIRTUALENV_CHAR=" 🐍" - else - VIRTUALENV_DETAILS="[$(basename $VIRTUAL_ENV)]" - VIRTUALENV_CHAR=" ⓔ" - fi - fi - - echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" + VIRTUALENV_DETAILS="" + VIRTUALENV_CHAR="" + + # $VIRTUAL_ENV is set and is non-zero length + if [[ -n "$VIRTUAL_ENV" ]]; then + # Check if Python 3 exists + if command -v python3 > /dev/null 2>&1; then + VIRTUALENV_DETAILS="$("$VIRTUAL_ENV/bin/python" --version | sed 's,Python ,,') on [$(basename "$VIRTUAL_ENV")]" + VIRTUALENV_CHAR=" 🐍" + else + VIRTUALENV_DETAILS="[$(basename "$VIRTUAL_ENV")]" + VIRTUALENV_CHAR=" ⓔ" + fi + fi + + echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" } # Rename tab function tabname { - printf "\e]1;$1\a" + printf "\e]1;%s\a" "$1" } # Rename window function winname { - printf "\e]2;$1\a" + printf "\e]2;%s\a" "$1" } _theme_clock() { @@ -92,8 +92,8 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"} # Displays the current prompt function prompt_command() { - PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${green}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white}${normal}\n${icon_end}" - PS2="${icon_end}" + PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green?}\u${normal}${icon_host}${bold_cyan?}\h${normal}${green?}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple?}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white?}${normal}\n${icon_end}" + PS2="${icon_end}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash index 8f3d5baf49..59f82a4a81 100644 --- a/themes/lambda/lambda.theme.bash +++ b/themes/lambda/lambda.theme.bash @@ -1,33 +1,35 @@ -#!/bin/bash +# shellcheck shell=bash # shellcheck disable=SC1090,SC2034 function set_prompt { - local user_color="\[\033[1;31m\]" # bold red for username - local at_color="\[\033[1;37m\]" # bold white for @ symbol - local host_color="\[\033[1;31m\]" # bold red for hostname - local in_color="\[\033[1;37m\]" # bold white for "in" - local dir_color="\[\033[1;35m\]" # bold purple for current working directory - local git_color="\[\033[1;36m\]" # bold cyan for Git information - local time_color="\[\033[1;32m\]" # bold green for time taken - local reset_color="\[\033[0m\]" # reset color - local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol + local user_color="\[\033[1;31m\]" # bold red for username + local at_color="\[\033[1;37m\]" # bold white for @ symbol + local host_color="\[\033[1;31m\]" # bold red for hostname + local in_color="\[\033[1;37m\]" # bold white for "in" + local dir_color="\[\033[1;35m\]" # bold purple for current working directory + local git_color="\[\033[1;36m\]" # bold cyan for Git information + local time_color="\[\033[1;32m\]" # bold green for time taken + local reset_color="\[\033[0m\]" # reset color + local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol - local end_time=$(date +%s%3N) # current time in milliseconds - local time_taken=$(( (end_time - start_time) )) # time in milliseconds + local end_time time_taken + end_time=$(date +%s%3N) # current time in milliseconds + # shellcheck disable=SC2154 + time_taken=$((end_time - start_time)) # time in milliseconds - PS1="${user_color}╭─\\u" # username - PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname - PS1+="${in_color} in" # "in" between hostname and current directory - PS1+="${dir_color} \\w" # current working directory + PS1="${user_color}╭─\\u" # username + PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname + PS1+="${in_color} in" # "in" between hostname and current directory + PS1+="${dir_color} \\w" # current working directory - # Git information (status symbol) - PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" + # Git information (status symbol) + PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" - if [ $time_taken -gt 0 ]; then - PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds - fi + if [ $time_taken -gt 0 ]; then + PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds + fi - PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after + PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after } PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' From 092b1ea9373a4a9a51cd0787747404f7e2e248d4 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 11:54:59 +0200 Subject: [PATCH 2/3] linting the bats --- test/plugins/cmd-returned-notify.plugin.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index d8aa9248ff..19965032aa 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -9,8 +9,9 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + export COMMAND_DURATION_START_SECONDS NOTIFY_IF_COMMAND_RETURNS_AFTER sleep 1 run precmd_return_notification assert_success @@ -18,8 +19,9 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + export COMMAND_DURATION_START_SECONDS NOTIFY_IF_COMMAND_RETURNS_AFTER sleep 1 run precmd_return_notification assert_success From 9df0c64a4936843a6907de1bbf5bf1e03c1f3027 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 11:58:10 +0200 Subject: [PATCH 3/3] linting the bats --- aliases/available/git.aliases.bash | 6 +++--- test/plugins/battery.plugin.bats | 1 + themes/base.theme.bash | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index f56675e66d..829505ddfd 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -83,7 +83,7 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' -alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. +alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. alias gprogress='git log --pretty=format:'\''%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d'\'' --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files @@ -153,8 +153,8 @@ alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosqu alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset -alias gus='git reset HEAD' # read as: 'git unstage' -alias grh='git reset' # equivalent to: git reset HEAD +alias gus='git reset HEAD' # read as: 'git unstage' +alias grh='git reset' # equivalent to: git reset HEAD alias grh!='git reset --hard' alias gpristine='git reset --hard && git clean -dfx' diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 49199ef27c..6665207f3a 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -271,6 +271,7 @@ function setup_ioreg { percent="$1" function ioreg { + # shellcheck disable=SC2317 printf "\"MaxCapacity\" = 100\n\"CurrentCapacity\" = %s" "${percent}" } } diff --git a/themes/base.theme.bash b/themes/base.theme.bash index e25014f86b..d78baa6adf 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -416,9 +416,9 @@ function node_version_prompt() { _log_debug "node: using version strategy '$NODE_VERSION_STRATEGY'" if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then - nvm_version_prompt + nvm_version_prompt elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then - node_native_version_prompt + node_native_version_prompt fi }