Skip to content

Commit d6bcedf

Browse files
committed
plugin/base: rewrite t() function to use todo.sh
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.
1 parent 02b57a8 commit d6bcedf

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

plugins/available/base.plugin.bash

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function passgen() {
6767

6868
# Create alias pass to passgen when pass isn't installed or
6969
# BASH_IT_LEGACY_PASS is true.
70-
if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then
70+
if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" == true ]]; then
7171
alias pass=passgen
7272
fi
7373

@@ -120,19 +120,26 @@ function usage() {
120120
esac
121121
}
122122

123-
if ! _bash-it-component-item-is-enabled plugin todo; then
124-
# if user has installed todo plugin, skip this...
125-
function t() {
126-
about 'one thing todo'
127-
param 'if not set, display todo item'
128-
param '1: todo text'
129-
if [[ "$*" == "" ]]; then
130-
cat ~/.t
131-
else
132-
echo "$*" > ~/.t
133-
fi
134-
}
135-
fi
123+
function t() {
124+
about 'todo.sh if available, otherwise one thing todo'
125+
param 'if not set, display todo item'
126+
param '1: todo text'
127+
128+
local todotxt="${XDG_STATE_HOME:-~/.local/state}/bash_it/todo.txt"
129+
130+
if _bash-it-component-item-is-enabled plugin todo; then
131+
todo.sh "$@"
132+
return
133+
elif [[ ! -f "${todotxt}" && -f ~/.t ]]; then
134+
mv -vn ~/.t "${todotxt}" # Verbose, so the user knows. Don't overwrite, just in case.
135+
fi
136+
137+
if [[ "$#" -eq 0 ]]; then
138+
cat "${todotxt}"
139+
else
140+
echo "$@" >| "${todotxt}"
141+
fi
142+
}
136143

137144
if _command_exists mkisofs; then
138145
function mkiso() {

plugins/available/todo.plugin.bash

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ about-plugin 'Todo.txt integration'
44
# you may override any of the exported variables below in your .bash_profile
55
: "${TODOTXT_DEFAULT_ACTION:=ls}"
66
export TODOTXT_DEFAULT_ACTION
7-
8-
alias t='todo.sh'

0 commit comments

Comments
 (0)