AuHau / toggl-cli

A simple command-line interface for toggl.com

Home Page:https://toggl.uhlir.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zsh/bash completion?

Voronenko opened this issue · comments

In source I observe some signs that tool had automated zsh/bash completion some time ago?
https://github.com/click-contrib/click-completion

So far I am using my self-written "dirty one" which tab completes almost all routine tasks, but if tool has some built-in completion generator - can you share way to activate it ?

https://github.com/Voronenko/dotfiles/blob/master/completions/_toggl.zsh

#compdef toggl

__toggl-workspaces() {
    toggl workspaces
}

__toggl-projects() {
    toggl projects | awk '{ print $2 }'
}

__toggl-now() {
    echo "''d1:20''"
    echo "'`date '+%Y-%m-%d %H:%M:%S'`'"
}

__toggl-duration() {
    echo "''d1:20''"
}

__toggl-recent-entries() {
    toggl ls | grep @ | awk -F'@' '{gsub(/^[ \t\r\n]+/, "", $1);gsub(/[ \t\r\n]+$/, "", $1);print "\""$1"\""}' | sort | uniq
}


_toggl-commands() {
  local -a commands

  commands=(
    'add: DESCR [:WORKSPACE] [@PROJECT | #PROJECT_ID] START_DATETIME (''d''DURATION | END_DATETIME) creates a completed time entry, DURATION = [[Hours:]Minutes:]Seconds'
    'add: DESCR [:WORKSPACE] [@PROJECT | #PROJECT_ID] ''d''DURATION creates a completed time entry, with start time DURATION ago, DURATION = [[Hours:]Minutes:]Seconds'
    'clients:lists all clients'
    'continue: [from DATETIME | ''d''DURATION] restarts the last entry, DURATION = [[Hours:]Minutes:]Seconds'
    'continue: DESCR [from DATETIME | ''d''DURATION] restarts the last entry matching DESCR'
    'ls:list recent time entries'
    'now:print what you''re working on now'
    'workspaces:lists all workspaces'
    'projects: [:WORKSPACE] lists all projects'
    'rm:delete a time entry by id'
    'start: DESCR [:WORKSPACE] [@PROJECT | #PROJECT_ID] [''d''DURATION | DATETIME] starts a new entry , DURATION = [[Hours:]Minutes:]Seconds'
    'stop:stops the current entry'
    'www:visits toggl.com'
  )

  _arguments -s : $nul_args && ret=0
  _describe -t commands 'toggl command' commands && ret=0
}


_toggl() {
  local -a nul_args
  nul_args=(
    '(-h --help)'{-h,--help}'[show help message and exit.]'
    '(-q --quiet)'{-q,--quiet}'[don''t print anything]'
    '(-v --verbose)'{-v,--verbose}'[print additional info]'
    '(-d --debug)'{-d,--debug}'[print debugging output]'
  )

  local curcontext=$curcontext ret=1

  if ((CURRENT == 2)); then
    _toggl-commands
  else
    shift words
    (( CURRENT -- ))
    curcontext="${curcontext%:*:*}:toggl-$words[1]:"
    case $words[1] in
    add)
      _arguments "2: :($(__toggl-workspaces))" \
                 "3: :($(__toggl-projects))" \
                 "4: :($(__toggl-now))" \
                 "5: :($(__toggl-duration))"
      ;;
    start)
      _arguments "2: :($(__toggl-workspaces))" \
                 "3: :($(__toggl-projects))" \
                 "4: :($(__toggl-now))"
      ;;
    stop)
      _arguments "1: :($(__toggl-now))"
      ;;
    projects)
      _arguments "1: :($(__toggl-workspaces))"
      ;;
    continue)
      _arguments "1: :($(__toggl-recent-entries))"
      ;;


    esac  fi
}

_toggl "$@"

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et

Hey there,

yes, this tool supports shell's autocompletion ;-) It is described in its documentation see: https://toggl.adam-uhlir.me/cli/#shell-completion

Thanks!

Btw installation is not healthy. @AuHau

Clean ubuntu 18.04 LTS (for example from digital ocean)

root@ubuntu-s-1vcpu-1gb-ams3-01:~# toggl
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pbr/version.py", line 442, in _get_version_from_pkg_resources
    provider = pkg_resources.get_provider(requirement)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 344, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'toggl' distribution was not found and is required by the application

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/toggl", line 7, in <module>
    from toggl.toggl import main
  File "/usr/local/lib/python3.6/dist-packages/toggl/__init__.py", line 3, in <module>
    VERSION = VersionInfo('toggl').semantic_version()
  File "/usr/local/lib/python3.6/dist-packages/pbr/version.py", line 462, in semantic_version
    self._semantic = self._get_version_from_pkg_resources()
  File "/usr/local/lib/python3.6/dist-packages/pbr/version.py", line 449, in _get_version_from_pkg_resources
    result_string = packaging.get_version(self.package)
  File "/usr/local/lib/python3.6/dist-packages/pbr/packaging.py", line 848, in get_version
    name=package_name))
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name toggl was given, but was not able to be found.