forked from todotxt/todo.txt-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: completion can use different todo.sh locations and configurations.
This was previously not supported; todo_completion always used plain todo.sh from the PATH. Now it's possible to override the used executable (and configuration used through _todo_sh, set from a completion function wrapper. Cp. http://tech.groups.yahoo.com/group/todotxt/message/4003
- Loading branch information
Showing
3 changed files
with
136 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
# | ||
|
||
test_description='Bash completion with different path functionality | ||
This test checks that todo_completion can use a different path to todo.sh when | ||
it is not accessible through PATH. | ||
' | ||
. ./test-lib.sh | ||
|
||
cat > todo.txt <<EOF | ||
(B) smell the +roses @outside @outdoor +shared | ||
notice the sunflowers +sunflowers @outside @garden +shared +landscape | ||
stop | ||
EOF | ||
|
||
mv bin/todo.sh bin/todo2.sh | ||
test_expect_success 'todo2.sh executable' 'todo2.sh list' | ||
|
||
# Define a second completion function that injects the different executable. In | ||
# real use, this would be installed via | ||
# complete -F _todo2 todo2.sh | ||
_todo2() | ||
{ | ||
local _todo_sh='todo2.sh' | ||
_todo "$@" | ||
} | ||
|
||
test_todo_custom_completion _todo2 'all todo2 contexts' 'todo2 list @' '@garden @outdoor @outside' | ||
|
||
|
||
|
||
# Remove the test environment's bin directory from the PATH, so that our test | ||
# executable must be launched with an explicit path. | ||
PATH=${PATH##"${PWD}/bin:"} | ||
test_expect_code 127 'todo2.sh executable not in PATH' 'todo2.sh' | ||
|
||
_todo2path() | ||
{ | ||
local _todo_sh='./bin/todo2.sh' | ||
_todo "$@" | ||
} | ||
test_todo_custom_completion _todo2path 'all todo2 contexts' 'todo2 list @' '@garden @outdoor @outside' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
# | ||
|
||
test_description='Bash completion with different aliases functionality | ||
This test checks that todo_completion can use a different configuration | ||
when another todo.sh alias is defined that uses that configuration. | ||
' | ||
. ./test-lib.sh | ||
|
||
cat > todo.txt <<EOF | ||
(B) smell the +roses @outside @outdoor +shared | ||
notice the sunflowers +sunflowers @outside @garden +shared +landscape | ||
stop | ||
EOF | ||
cat > todo2.txt <<EOF | ||
+herbs @oriental buy spices | ||
+slack @home watch tv | ||
EOF | ||
|
||
cp todo.cfg todo2.cfg | ||
cat >> todo2.cfg <<'EOF' | ||
export TODO_FILE="$TODO_DIR/todo2.txt" | ||
EOF | ||
|
||
# Note: We cannot use aliases within the test framework, but functions are | ||
# equivalent and work fine. | ||
todo1() | ||
{ | ||
todo.sh "$@" | ||
} | ||
todo2() | ||
{ | ||
todo.sh -d "$HOME/todo2.cfg" "$@" | ||
} | ||
|
||
# Ensure that the test fixture works as planned. | ||
test_todo_session 'todo 1 and 2 contexts' <<EOF | ||
>>> todo1 listcon | ||
@garden | ||
@outdoor | ||
@outside | ||
>>> todo2 listcon | ||
@home | ||
@oriental | ||
EOF | ||
|
||
|
||
# Define a second completion function that injects the different configuration | ||
# file. In real use, this would be installed via | ||
# complete -F _todo2 todo2 | ||
_todo2() | ||
{ | ||
local _todo_sh='todo.sh -d "$HOME/todo2.cfg"' | ||
_todo "$@" | ||
} | ||
|
||
test_todo_completion 'all todo1 contexts' 'todo1 list @' '@garden @outdoor @outside' | ||
test_todo_custom_completion _todo2 'all todo2 contexts' 'todo2 list @' '@home @oriental' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters