nikolassv / bartib

A simple timetracker for the command line. It saves a log of all tracked activities as a plaintext file and allows you to create flexible reports.
GNU General Public License v3.0
687 stars 36 forks source link

Unquote output of bartib projects? #36

Closed neezer closed 6 months ago

neezer commented 10 months ago

Often I want to start more work on an existing project—non-contiguous, so bartib continue isn't a good fit—and I don't want to retype the name of the project.

I've been doing this with fzf but I have to manually scrub-out the quotes, eg.

bartib start -p "`bartib projects | fzf | tr -d '"'`" -d "whatever"

What I'd like to do is this:

bartib start -p "`bartib projects | fzf`" -d "whatever"

... but presently that double-quotes the project name in the bartib file.

Maybe I'm getting some shell wizardry wrong, but I feel like this would all be easier of bartib projects just outputted lines of text instead of quoted lines of text.

nikolassv commented 10 months ago

I never considered piping the project list to fzf. That is a neat idea! I will definitely incorporate that into my workflow.

The reason for the quotes around the project names is that I needed them for the autocompletion script in bash: https://github.com/nikolassv/bartib/blob/master/misc/bartibCompletion.sh. For the autocompletion, I needed each project name as a distinct string. Perhaps there is some better way to achieve this, but I wouldn't change the behavior of that command now as other users scripts may depend on it.

Perhaps it is feasible for you to create an alias or a bash function to start a new activity and select the desired project?

neezer commented 10 months ago

For the autocompletion, I needed each project name as a distinct string.

I tried manually unquoting the project list and using the bash completion, and it worked the same?

I think because IFS is set to \n and the script is using -W, completion terms are already being split by newlines regardless of quotes.

# create a project list without quotes
bartib projects | sed -e 's/^"//' -e 's/"$//' > test.txt

# change completion to use unquoted list
sed -i \
  's/ALL_PROJECTS=.*$/ALL_PROJECTS=\`cat test.txt\`/' \
  bartibCompletion.sh

# source the update
source bartibCompletion.sh

# try it out
bartib start -p proj<TAB>

I tested with project names with & without spaces, and in both cases it appeared to work... suggesting maybe the quotes aren't necessary for bartib projects? Is there some nuance I'm missing?

nikolassv commented 10 months ago

Thank you for trying it out. I will take another look at it. Perhaps the completion script can indeed work without the quotes.

Still, I would avoid changing the standard behavior, as this may break someone else's script. Perhaps we could add a --no-quotes flag to the bartib projects subcommand to suppress the quotes instead.