dnote icon indicating copy to clipboard operation
dnote copied to clipboard

autocompletion

Open sungwoncho opened this issue 7 years ago • 5 comments

Autocompletion of book names

$ dnote v j<hit tab>
$ dnote v javascript<hit tab>
$ dnote v js
# ...

sungwoncho avatar Sep 01 '18 01:09 sungwoncho

This is a bit tricky as this depends on the shell you want to provide autocompletions for. Bash and zsh sound like a good place to start, but I'm not 100% how things work on Windows.

michielboekhoff avatar Sep 17 '18 14:09 michielboekhoff

@sungwoncho - is Windows within scope for this issue? I can help with the zsh and bash completion scripts, but have no experience with Windows.

michielboekhoff avatar Dec 13 '18 11:12 michielboekhoff

I think zsh and bash is a good place to start.

sungwoncho avatar Dec 13 '18 20:12 sungwoncho

I have implemented bash and zsh completion in #193 and opened a PR to include it in oh-my-zsh https://github.com/robbyrussell/oh-my-zsh/pull/7885.

If you have any suggestions on how we can make the autocompletion available and just work, please let me know. I'm thinking maybe installation script should place the autocompletion scripts in appropriate places but that might require sudo.

sungwoncho avatar May 27 '19 11:05 sungwoncho

On bash, I'm using this: /usr/local/etc/bash_completion.d/dnote

# bash completion for dnote

have dnote &&
_dnote()
{
  local cur prev
  COMPREPLY=()
  _get_comp_words_by_ref cur prev

  case $prev in
    v|view|a|add)
      COMPREPLY=( $( compgen  -W '$(dnote view --name-only)' -- "$cur" ) )
      return 0
      ;;
  esac

  COMPREPLY=( $( compgen -W '$( dnote -h | grep "^ *[a-z]\+" -o )' -- "$cur"))
} && complete -F _dnote dnote

artburkart avatar Sep 29 '19 17:09 artburkart

This has been implemented.

  • Bash: https://github.com/dnote/dnote/blob/b47c792d5fcf610db103ab49c57862e49333e13f/pkg/cli/dnote-completion.bash
  • Zsh: https://github.com/dnote/dnote/blob/b47c792d5fcf610db103ab49c57862e49333e13f/pkg/cli/dnote-completion.zsh
  • Documentation: https://github.com/dnote/dnote/wiki/Dnote-CLI#auto-completion

Also, oh-my-zsh comes with Dnote auto-completion plugin directly.

sungwoncho avatar Mar 12 '23 02:03 sungwoncho