Skip to content
This repository was archived by the owner on Apr 27, 2022. It is now read-only.

Commit 8e95861

Browse files
author
Wolfgang Pappa
committed
Add command line completion for fish
Info about fish: https://fishshell.com/
1 parent d76bc45 commit 8e95861

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ Hey, tolino developers at Telekom / T-Systems, please look at
6161
the comments in tolinocloud.py. It'd be really nice to get the
6262
specifications for the REST API. Thanks!
6363

64+
Command Line Completion
65+
=======================
66+
67+
If you like command line completion [fish](https://fishshell.com/), you can copy the file `tolinoclient.py.fish` into `~/.config/fish/completions/` (create the directory if needed).
68+
6469
License
6570
=======
6671

tolinoclient.py.fish

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env fish
2+
#
3+
# Commandline completion in fish for tolinoclient.py
4+
#
5+
# Author: Wolfgang Pappa
6+
# Date: June 2018
7+
8+
set PROG 'tolinoclient.py'
9+
10+
# Check whether a subcommand is still needed.
11+
function __fish_tolino_needs_command
12+
set -l cmd (commandline -opc)
13+
if [ (count $cmd) -eq 1 -a $cmd[1] = $PROG ]
14+
return 0
15+
end
16+
return 1
17+
end
18+
19+
# Check whether any of the given subcommands has been entered.
20+
function __fish_tolino_uses_command
21+
set cmd (commandline -opc)
22+
if [ (count $cmd) -gt 1 ]
23+
# Check if any of the arguments is a subcommand
24+
for a in $argv
25+
if [ $a = $cmd[2] ]
26+
return 0 # subcommand found!
27+
end
28+
end
29+
end
30+
return 1 # no success
31+
end
32+
33+
# List possible partners IDs.
34+
# A tab separates the arguments from the description.
35+
function __fish_tolino_partners
36+
echo "0 List partners"
37+
echo "3 thalia.de"
38+
echo "6 buch.de"
39+
echo "13 hugendubel.de"
40+
end
41+
42+
# Init
43+
complete -c $PROG --erase # deletes any other completion
44+
complete -c $PROG --no-files
45+
46+
# Subcommands
47+
complete -c $PROG -n '__fish_tolino_needs_command' -a 'inventory' -d 'Fetch and print inventory'
48+
complete -c $PROG -n '__fish_tolino_needs_command' -a 'upload' -d 'Upload a file (must be either .pdf or .epub)'
49+
complete -c $PROG -n '__fish_tolino_needs_command' -a 'download' -d 'Download a document'
50+
complete -c $PROG -n '__fish_tolino_needs_command' -a 'delete' -d 'Delete a document (be careful!)'
51+
complete -c $PROG -n '__fish_tolino_needs_command' -a 'devices' -d 'List devices registered to cloud account'
52+
complete -c $PROG -n '__fish_tolino_needs_command' -a 'unregister' -d 'Unregister device from cloud account (be careful!)'
53+
54+
# Options and flags
55+
complete -c $PROG -s h -l help -d 'Show help message and exit'
56+
complete -c $PROG -l user -d 'username (usually an email address)' -x
57+
complete -c $PROG -l config -d 'config file (default: .tolinoclientrc)' -r
58+
complete -c $PROG -l password -d 'password' -x
59+
complete -c $PROG -l partner -d 'shop/partner ID' -x -a "(__fish_tolino_partners)"
60+
complete -c $PROG -l debug -d 'Log additional debugging info'
61+
62+
# Completion for parameters and subcommands
63+
complete -c $PROG -n '__fish_tolino_uses_command upload' -a "(__fish_complete_path)" -x

0 commit comments

Comments
 (0)