Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Changed from .tasks to ./local/lib/tasks #15

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion completions/tasks.fish
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ complete -c tasks -n "not __fish_seen_subcommand_from $commands" \

# auto-complete for tasks use
complete -c tasks -n "__fish_seen_subcommand_from use"\
-a "(ls ~/.tasks/lists)"
-a "(ls $HOME/.local/lib/tasks/lists)"

# auto-complete for tasks tear
complete -c tasks -n "__fish_seen_subcommand_from tear"\
-a "(ls $HOME/.local/lib/tasks/lists)"
6 changes: 3 additions & 3 deletions src/add.fish
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function add
argparse 'l/link=+' 'L/list=' -- $argv
set -x lines (echo -n $argv[2..-1]| md5sum | cut -d " " -f 1| cut -b -7)
echo -n "$lines $argv[2..-1] |" >> ~/.tasks/lists/$_flag_list/Tdo.csv
echo -n "$lines $argv[2..-1] |" >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
if set -q _flag_link
for i in $_flag_link
set -x link (echo -e "\e]8;;$i\aResource\e]8;;\a")
echo -n , $link >> ~/.tasks/lists/$_flag_list/Tdo.csv
echo -n , $link >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
end
end
echo >> ~/.tasks/lists/$_flag_list/Tdo.csv
echo >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
end
4 changes: 2 additions & 2 deletions src/addAt.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function addAt
argparse 'l/link=+' 'L/list=' 'n/index=' -- $argv
set -x max (wc -l ~/.tasks/lists/$_flag_list/Tdo.csv | cut -d " " -f 1)
set -x max (wc -l $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | cut -d " " -f 1)
if test -z "$_flag_index"
echo "Please use --index or n followed by appropriate index"
exit
Expand All @@ -18,5 +18,5 @@ function addAt
set -x link $link(echo -e " \e]8;;$i\aResource\e]8;;\a")
end
end
sed -i "$_flag_index i $lines $argv[2..-1] $link" ~/.tasks/lists/$_flag_list/Tdo.csv
sed -i "$_flag_index i $lines $argv[2..-1] $link" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
end
16 changes: 8 additions & 8 deletions src/delete.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function delete

argparse 'H/hash=?' "n/index=" "L/list=" -- $argv
set -x max (wc -l ~/.tasks/lists/$_flag_list/Tdo.csv | cut -d " " -f 1)
set -x max (wc -l $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | cut -d " " -f 1)
if test -n "$_flag_index"
if [ $_flag_index -gt $max ]
echo "$_flag_index is beyond the size of list"
Expand All @@ -12,26 +12,26 @@ function delete
end
end
if set -q _flag_index
sed -i "$_flag_index d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed -i "$_flag_index d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
else if set -q _flag_hash
set -x num (grep -n $_flag_hash ~/.tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
set -x num (grep -n $_flag_hash $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
if test -n "$num"
sed -i "$num d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed -i "$num d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
else
echo No such hash exists
end
else if test -n $argv[2]
set -x num (grep -n "$argv[2..-1]" ~/.tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
set -x num (grep -n "$argv[2..-1]" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
if test -n "$num"
sed "$num !d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed "$num !d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
echo "Do you want to delete this?"
read -l -P 'Confirm [y]/n: ' confirm
switch $confirm
case N n
exit
end
sed "$num !d" ~/.tasks/lists/$_flag_list/Tdo.csv >> ~/.tasks/lists/$_flag_list/Tdone.csv
sed -i "$num d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed "$num !d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdone.csv
sed -i "$num d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
else
echo "Unable to find keyword"
end
Expand Down
20 changes: 10 additions & 10 deletions src/done.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function done
argparse 'H/hash=?' "n/index=" "L/list=" -- $argv
set -x max (wc -l ~/.tasks/lists/$_flag_list/Tdo.csv | cut -d " " -f 1)
set -x max (wc -l $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | cut -d " " -f 1)
if test -n "$_flag_index"
if [ $_flag_index -gt $max ]
echo "$_flag_index is beyond the size of list"
Expand All @@ -11,28 +11,28 @@ function done
end
end
if set -q _flag_index
sed "$_flag_index !d" ~/.tasks/lists/$_flag_list/Tdo.csv >> ~/.tasks/lists/$_flag_list/Tdone.csv
sed -i "$_flag_index d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed "$_flag_index !d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdone.csv
sed -i "$_flag_index d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
else if set -q _flag_hash
set -x num (grep -n $_flag_hash ~/.tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
set -x num (grep -n $_flag_hash $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
if test -n "$num"
sed "$num !d" ~/.tasks/lists/$_flag_list/Tdo.csv >> ~/.tasks/lists/$_flag_list/Tdone.csv
sed -i "$num d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed "$num !d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdone.csv
sed -i "$num d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
else
echo "No such hash exists"
end
else if test -n $argv[2]
set -x num (grep -n "$argv[2..-1]" ~/.tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
set -x num (grep -n "$argv[2..-1]" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv | head -n 1 | cut -d ":" -f 1)
if test -n "$num"
sed "$num !d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed "$num !d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
echo "Do you want to move this to Done list?"
read -l -P 'Confirm [y]/n: ' confirm
switch $confirm
case N n
exit
end
sed "$num !d" ~/.tasks/lists/$_flag_list/Tdo.csv >> ~/.tasks/lists/$_flag_list/Tdone.csv
sed -i "$num d" ~/.tasks/lists/$_flag_list/Tdo.csv
sed "$num !d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv >> $HOME/.local/lib/tasks/lists/$_flag_list/Tdone.csv
sed -i "$num d" $HOME/.local/lib/tasks/lists/$_flag_list/Tdo.csv
else
echo "Unable to find keyword"
end
Expand Down
38 changes: 20 additions & 18 deletions tasks
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
# something like tasks clean, here cmd will be set as "clean"
set -x cmd $argv[1]

# tasks directory
set -x tasksDir "$HOME/.local/lib/tasks"
# sourcing all the function from src
source ~/.tasks/src/add.fish
source ~/.tasks/src/addAt.fish
source ~/.tasks/src/delete.fish
source ~/.tasks/src/done.fish
source ~/.tasks/meta/env
source $tasksDir/src/add.fish
source $tasksDir/src/addAt.fish
source $tasksDir/src/delete.fish
source $tasksDir/src/done.fish
source $tasksDir/meta/env

# switch case to determine the command
switch $cmd

# empty case, when the command is just $ tasks
case ''
~/.tasks/src/./base
$tasksDir/src/./base

# this requires improvements, it opens the readme
case "--help" "-h" "help"
Expand All @@ -29,7 +31,7 @@ switch $cmd
# used to create a new list
case create
if test -n $argv[2]
set dir ~/.tasks/lists/"$argv[2..-1]"
set dir $tasksDir/lists/"$argv[2..-1]"
[ -d "$dir" ] && echo "list already exists" && exit
mkdir "$dir"
touch "$dir"/Tdo.csv
Expand All @@ -45,17 +47,17 @@ switch $cmd
echo cannot tear base list
exit
end
set dir ~/.tasks/lists/"$argv[2..-1]"
set dir $tasksDir/lists/"$argv[2..-1]"
[ ! -d "$dir" ] && echo "list doesn't exist" && exit
rm -r "$dir"
echo set list base > ~/.tasks/meta/env
echo set list base > $tasksDir/meta/env
else
echo "tasks tear ... what?"
end

# this will show all the lists
case list
set thelists (ls ~/.tasks/lists/)
set thelists (ls $tasksDir/lists/)
for i in $thelists
if [ "$list" = $i ]
echo -n "*"
Expand All @@ -66,10 +68,10 @@ switch $cmd
# to switch to a list
case use
if test -n $argv[2]
set dir ~/.tasks/lists/"$argv[2..-1]"
set dir $tasksDir/lists/"$argv[2..-1]"
# echo $dir
[ ! -d "$dir" ] && echo "No such lists exists" && exit
echo set list "$argv[2..-1]" > ~/.tasks/meta/env
echo set list "$argv[2..-1]" > $tasksDir/meta/env
echo Using "$argv[2..-1]"
else
echo "tasks use ... what?"
Expand Down Expand Up @@ -103,26 +105,26 @@ switch $cmd

# resets the to-do and done sublists
case clear clean
cat /dev/null > ~/.tasks/lists/"$list"/Tdone.csv
cat /dev/null > ~/.tasks/lists/"$list"/Tdo.csv
cat /dev/null > $tasksDir/lists/"$list"/Tdone.csv
cat /dev/null > $tasksDir/lists/"$list"/Tdo.csv

# clears the to-do list
case clearDo cleanDo
cat /dev/null > ~/.tasks/lists/"$list"/Tdo.csv
cat /dev/null > $tasksDir/lists/"$list"/Tdo.csv

# clears the done list
case clearDone cleanDone
cat /dev/null > ~/.tasks/lists/"$list"/Tdone.csv
cat /dev/null > $tasksDir/lists/"$list"/Tdone.csv

# lists all the tasks in to-do list
case display show
echo "list:" $list
cat -n ~/.tasks/lists/"$list"/Tdo.csv
cat -n $tasksDir/lists/"$list"/Tdo.csv

# lists all the done tasks
case displayDone showDone
echo "list:" $list
cat -n ~/.tasks/lists/"$list"/Tdone.csv
cat -n $tasksDir/lists/"$list"/Tdone.csv

# unrecognized command
case '*'
Expand Down
8 changes: 4 additions & 4 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/fish

# removing tab completions for tasks
rm ~/.local/share/fish/generated_completions/tasks.fish
rm $HOME/.local/share/fish/generated_completions/tasks.fish
# removing manual for tasks
rm ~/.local/share/man/man1/tasks.1.gz
rm $HOME/.local/share/man/man1/tasks.1.gz
# removing tasks executable
rm ~/.local/bin/tasks
rm $HOME/.local/bin/tasks
# removing directory from lib
rm -r ~/.local/lib/tasks
rm -r $HOME/.local/lib/tasks