Improve autocompletion for t command

main
Ensar Sarajčić 2023-08-12 20:54:10 +02:00
parent b249e237b6
commit e1157e455f
2 changed files with 10 additions and 13 deletions

View File

@ -120,20 +120,15 @@ if [ -z "$TIMESHEET_LEDGER_HOME" ]; then
fi
time_in () {
PROJECT=$1
COMMENT=$2
LAST_ENTRY=$(grep "$PROJECT" "$TIMESHEET_LEDGER_HOME/timesheets/$(date +%Y).journal" | tail -1 | cut -f1 -d ' ')
if [ "$LAST_ENTRY" = "i" ]; then
echo "Timer for project $PROJECT was already started. Aborting..."
exit 1
fi
echo "i $(date '+%Y-%m-%d %H:%M:%S') $PROJECT $COMMENT" >> "$TIMESHEET_LEDGER_HOME/timesheets/$(date +%Y).journal"
echo "i $(date '+%Y-%m-%d %H:%M:%S') $PROJECT $COMMENT" >> "$TIMESHEET_LEDGER_HOME/timesheets/$(date +%Y).journal"
}
time_out () {
PROJECT=$1
LAST_ENTRY=$(grep "$PROJECT" "$TIMESHEET_LEDGER_HOME/timesheets/$(date +%Y).journal" | tail -1 | cut -f1 -d ' ')
if [ -z "$LAST_ENTRY" ]; then
echo "Timer for project $PROJECT is not started. Aborting..."
@ -147,20 +142,18 @@ time_out () {
}
time_bal () {
PROJECT=$1
ledger -f "$TIMESHEET_LEDGER_HOME/main.journal" bal $1
ledger -f "$TIMESHEET_LEDGER_HOME/main.journal" bal $PROJECT
}
case $COMMAND in
in)
time_in $PROJECT $COMMENT
time_in
;;
out)
time_out $PROJECT
time_out
;;
bal)
time_bal $PROJECT
time_bal
;;
*)
usage $COMMAND; exit 1 ;;

View File

@ -2,6 +2,10 @@ function __fish-timesheets-available-projects
grep 'account Project:.*' "$TIMESHEET_LEDGER_HOME/config/02_accounts.dat" | cut -f2 -d ' '
end
function __fish-timesheets-running-projects
cat "$TIMESHEET_LEDGER_HOME/timesheets/$(date +%Y).journal" | grep -v ';' | awk '{ last[$4] = $1 } END { for (i in last) { if (last[i] == "i") { print i } } }'
end
function __fish-timesheets-existing-comments
ledger -f "$TIMESHEET_LEDGER_HOME/main.journal" payees ^Project
end
@ -22,7 +26,7 @@ complete -c t -x -n "__fish_seen_subcommand_from in" -n "__fish_timesheets_arg_n
complete -c t -x -n "__fish_seen_subcommand_from in" -n "__fish_timesheets_arg_number 3" -a '(__fish-timesheets-existing-comments)'
# Out
complete -c t -x -n "__fish_seen_subcommand_from out" -a '(__fish-timesheets-available-projects)'
complete -c t -x -n "__fish_seen_subcommand_from out" -a '(__fish-timesheets-running-projects)'
# Bal
complete -c t -x -n "__fish_seen_subcommand_from bal" -a '(__fish-timesheets-available-projects)'