bartib icon indicating copy to clipboard operation
bartib copied to clipboard

Unquote output of bartib projects?

Open neezer opened this issue 1 year ago • 3 comments

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.

neezer avatar Jan 05 '24 23:01 neezer

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?

nikolassv avatar Jan 08 '24 17:01 nikolassv

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?

neezer avatar Jan 10 '24 17:01 neezer

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.

nikolassv avatar Jan 23 '24 08:01 nikolassv