From 02b57a83ef2ab29d8c7e04d3a98b92b1223c8fb4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 27 Dec 2021 12:53:36 -0800 Subject: [PATCH 1/2] plugins/todo: lint plugin/base: use `_bash-it-component-item-is-enabled()` --- clean_files.txt | 1 + plugins/available/base.plugin.bash | 3 +-- plugins/available/todo.plugin.bash | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8c8b3fed..8ee63959 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -109,6 +109,7 @@ plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash +plugins/available/todo.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index a4ce0c39..1efe4cca 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -120,8 +120,7 @@ function usage() { esac } -# shellcheck disable=SC2144 # the glob matches only one file -if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" && ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then +if ! _bash-it-component-item-is-enabled plugin todo; then # if user has installed todo plugin, skip this... function t() { about 'one thing todo' diff --git a/plugins/available/todo.plugin.bash b/plugins/available/todo.plugin.bash index cf1479e2..be4806c2 100644 --- a/plugins/available/todo.plugin.bash +++ b/plugins/available/todo.plugin.bash @@ -1,12 +1,8 @@ -#!/bin/bash -cite about-plugin +# shellcheck shell=bash about-plugin 'Todo.txt integration' # you may override any of the exported variables below in your .bash_profile - -if [ -z "$TODOTXT_DEFAULT_ACTION" ]; then - # typing 't' by itself will list current todos - export TODOTXT_DEFAULT_ACTION=ls -fi +: "${TODOTXT_DEFAULT_ACTION:=ls}" +export TODOTXT_DEFAULT_ACTION alias t='todo.sh' From d6bcedfa96e397246d0aa9e50823864021562890 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 30 Dec 2021 22:52:16 -0800 Subject: [PATCH 2/2] plugin/base: rewrite `t()` function to use `todo.sh` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the test for whether `plugin/todo` is enabled inside the function, and remove the alias from there. Alsö, respect `$XDG_STATE_HOME` and move the old `~/.t` file if it exists. --- plugins/available/base.plugin.bash | 35 ++++++++++++++++++------------ plugins/available/todo.plugin.bash | 2 -- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 1efe4cca..1a905163 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -67,7 +67,7 @@ function passgen() { # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then +if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" == true ]]; then alias pass=passgen fi @@ -120,19 +120,26 @@ function usage() { esac } -if ! _bash-it-component-item-is-enabled plugin todo; then - # if user has installed todo plugin, skip this... - function t() { - about 'one thing todo' - param 'if not set, display todo item' - param '1: todo text' - if [[ "$*" == "" ]]; then - cat ~/.t - else - echo "$*" > ~/.t - fi - } -fi +function t() { + about 'todo.sh if available, otherwise one thing todo' + param 'if not set, display todo item' + param '1: todo text' + + local todotxt="${XDG_STATE_HOME:-~/.local/state}/bash_it/todo.txt" + + if _bash-it-component-item-is-enabled plugin todo; then + todo.sh "$@" + return + elif [[ ! -f "${todotxt}" && -f ~/.t ]]; then + mv -vn ~/.t "${todotxt}" # Verbose, so the user knows. Don't overwrite, just in case. + fi + + if [[ "$#" -eq 0 ]]; then + cat "${todotxt}" + else + echo "$@" >| "${todotxt}" + fi +} if _command_exists mkisofs; then function mkiso() { diff --git a/plugins/available/todo.plugin.bash b/plugins/available/todo.plugin.bash index be4806c2..6b495274 100644 --- a/plugins/available/todo.plugin.bash +++ b/plugins/available/todo.plugin.bash @@ -4,5 +4,3 @@ about-plugin 'Todo.txt integration' # you may override any of the exported variables below in your .bash_profile : "${TODOTXT_DEFAULT_ACTION:=ls}" export TODOTXT_DEFAULT_ACTION - -alias t='todo.sh'