Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress bar emitting unwanted characters to stderr #233

Closed
pkazmier opened this issue Jul 3, 2022 · 2 comments · Fixed by #234
Closed

Progress bar emitting unwanted characters to stderr #233

pkazmier opened this issue Jul 3, 2022 · 2 comments · Fixed by #234

Comments

@pkazmier
Copy link
Contributor

pkazmier commented Jul 3, 2022

Thank you for this amazing tool. I just discovered this and have been having fun trying to figure out how to integrate it into my daily workflow. The documentation is fantastic and I love the zk-nvim integration.

While working on a dynamic zsh auto completion function for zk, I discovered that zk emits unwanted characters to stderr due to bar.Clear() on line 89 of notebook.go. Even on the simplest run of zk command, it always generates output to stderr. For example:

$ zk 2> err.txt
Usage: zk <command> ...

$ od -c err.txt
0000000   \r  \r                                                        
0000002

It would be nice to have an option to disable the use of progressbar for those using zk in scripts and such. For now, I've resorted to redirecting stderr to /dev/null in my zsh auto completer. Without it, the auto completer formatting was broken due to those extra carriage returns emitted.

For those interested, I wrote a simple auto completer for a custom zk alias of mine called 1on1. As a manager, I use this to take notes when I have my bi-weekly one on ones with associates. I have a folder in my notebook called meetings and a group called 1_on_1 that uses a custom template with this headline # {{date now "%Y-%m-%d"}}: {{title}} 1:1. Then I have an alias called 1on1 that expands to zk new --title "$*" meetings. When I am about to meet with an associate, I execute zk 1on1 John Smith for example. I then wanted to build an auto completer so I could tab after typing zk 1on1 and be presented with a list of anyone I've had a prior 1:1 with. So, in my .zshrc file, I wrote the following to list all my one on one note titles and parse out the person's name from it:

function _zk {
  local state line
  _arguments "1: :(init index new list graph edit tag 1on1)" "2:Person:->names"
  case $state in
    names)
      case $line[1] in
        1on1)
          _values 'Names' "${(@f)$(zk list -q -f '{{title}}' -t 1_on_1 2> /dev/null | sed 's/....-..-..: \(.*\) 1:1/\1/' | sort -u)}"
            ;;
        esac
        ;;
    esac
}
compdef _zk zk

With that, I now have auto completion and a snazzy new workflow for all of my one on ones.

It took me hours to make this work only because I've never done any zsh auto completion before, but mostly because I had no idea why the formatting of the auto completion was busted when using zk. After eliminating pieces, I finally realized that zk was outputting characters to stderr, which ultimately was the root cause of my issue.

@mickael-menu
Copy link
Member

Thanks, custom auto-completion is a nice add-on!

I addressed this issue in #234. Basically the progress bar won't be shown anymore if you either:

  • Use the --no-input flag, or
  • Run the script in a non-interactive shell, e.g. using exec <&-:
    #!/bin/sh
    exec <&-
    zk list

Let me know if that helps and I'll merge this in main.

@pkazmier
Copy link
Contributor Author

pkazmier commented Jul 5, 2022

Works great. Thank you again for such a great tool. I love the neovim integration as well. Everything is so well done and documented.

@pkazmier pkazmier closed this as completed Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants