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

add completion support (Issue: #454) #460

Merged
merged 7 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DC ?= dmd
RELEASEVER = v2.3.2
pkgconfig := $(shell if [ $(PKGCONFIG) ] && [ "$(PKGCONFIG)" != 0 ] ; then echo 1 ; else echo "" ; fi)
notifications := $(shell if [ $(NOTIFICATIONS) ] && [ "$(NOTIFICATIONS)" != 0 ] ; then echo 1 ; else echo "" ; fi)
completions := $(shell if [ $(COMPLETIONS) ] && [ "$(COMPLETIONS)" != 0 ] ; then echo 1 ; else echo "" ; fi)
gitversion := $(shell if [ -f .git/HEAD ] ; then echo 1 ; else echo "" ; fi)

ifeq ($(pkgconfig),1)
Expand Down Expand Up @@ -35,6 +36,16 @@ DFLAGS += -debug -gs
endif
endif

# set up completion directories
ifeq ($(completions),1)
ifeq ($(pkgconfig),1)
BASHCOMPLETIONDIR ?= $(shell pkg-config --variable=completionsdir bash-completion)
else
BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
endif
ZSHCOMPLETIONDIR ?= /usr/local/share/zsh/site-functions
endif

DFLAGS += -w -g -ofonedrive -O $(NOTIF_VERSIONS) $(LIBS) -J.

PREFIX ?= /usr/local
Expand Down Expand Up @@ -110,6 +121,10 @@ else
install -D -m 644 onedrive@.service $(DESTDIR)/usr/lib/systemd/system/
install -D -m 644 onedrive.service $(DESTDIR)/usr/lib/systemd/user/onedrive.service
endif
ifeq ($(completions),1)
install -D -m 644 completions/complete.zsh $(DESTDIR)$(ZSHCOMPLETIONDIR)/_onedrive
install -D -m 644 completions/complete.bash $(DESTDIR)$(BASHCOMPLETIONDIR)/onedrive
endif

onedrive.service:
sed "s|@PREFIX@|$(PREFIX)|g" systemd.units/onedrive.service.in > onedrive.service
Expand All @@ -134,10 +149,14 @@ else
endif
for i in $(DOCFILES) ; do rm -f $(DESTDIR)$(DOCDIR)/$$i ; done
rm -f $(DESTDIR)$(MANDIR)/onedrive.1
ifeq ($(completions),1)
rm -f $(DESTDIR)$(ZSHCOMPLETIONDIR)/_onedrive
rm -f $(DESTDIR)$(BASHCOMPLETIONDIR)/onedrive
endif

version:
ifeq ($(gitversion),1)
echo $(shell git describe --tags) > version
else
echo $(RELEASEVER) > version
endif
endif
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ libraries are `gmodule-2.0`, `glib-2.0`, and `notify`.
By passing `DEBUG=1` to the `make` call, `onedrive` gets built with additional debug
information, useful (for example) to get `perf`-issued figures.

By passing `COMPLETIONS=1` to the `make` call, shell completion functions are
installed for `bash` and `zsh`. The installation directories are determined
as far as possible automatically, but can be overridden by setting the
environment variables `BASHCOMPLETIONDIR` and `ZSHCOMPLETIONDIR`.

### Building using a different compiler (for example [LDC](https://wiki.dlang.org/LDC))
#### Debian - i386 / i686
```text
Expand Down
42 changes: 42 additions & 0 deletions completions/complete.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# BASH completion code for OneDrive Linux Client
# (c) 2019 Norbert Preining
# License: GPLv3+ (as with the rest of the OneDrive Linux client project)

_onedrive()
{
local cur prev

COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}

options='--check-for-nomount --check-for-nosync --debug-https --disable-notifications --display-config --display-sync-status -d --download-only --disable-upload-validation --dry-run --enable-logging --force-http-1.1 --local-first --logout -m --monitor --no-remote-delete --print-token --resync --skip-dot-files --skip-symlinks --synchronize --upload-only -v --verbose --version -h --help'
argopts='--create-directory --get-O365-drive-id --remove-directory --single-directory --source-directory'

# Loop on the arguments to manage conflicting options
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
#exclude some mutually exclusive options
[[ ${COMP_WORDS[i]} == '--synchronize' ]] && options=${options/--monitor}
[[ ${COMP_WORDS[i]} == '--monitor' ]] && options=${options/--synchronize}
done

case "$prev" in
--confdir|--syncdir)
_filedir
return 0
;;
--create-directory|--get-O365-drive-id|--remove-directory|--single-directory|--source-directory)
return 0
;;
*)
COMPREPLY=( $( compgen -W "$options $argopts" -- $cur))
return 0
;;
esac

# notreached
return 0
}
complete -F _onedrive onedrive
44 changes: 44 additions & 0 deletions completions/complete.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#compdef onedrive
#
# ZSH completion code for OneDrive Linux Client
# (c) 2019 Norbert Preining
# License: GPLv3+ (as with the rest of the OneDrive Linux client project)

local -a all_opts
all_opts=(
'--check-for-nomount[Check for the presence of .nosync in the syncdir root. If found, do not perform sync.]'
'--check-for-nosync[Check for the presence of .nosync in each directory. If found, skip directory from sync.]'
'--confdir[Set the directory used to store the configuration files]:config directory:_files -/'
'--create-directory[Create a directory on OneDrive - no sync will be performed.]:directory name:'
'--debug-https[Debug OneDrive HTTPS communication.]'
'--destination-directory[Destination directory for renamed or move on OneDrive - no sync will be performed.]:directory name:'
'--disable-notifications[Do not use desktop notifications in monitor mode.]'
'--display-config[Display what options the client will use as currently configured - no sync will be performed.]'
'--display-sync-status[Display the sync status of the client - no sync will be performed.]'
'(-d --download-only)'{-d,--download-only}'[Only download remote changes]'
'--disable-upload-validation[Disable upload validation when uploading to OneDrive]'
'--dry-run[Perform a trial sync with no changes made]'
'--enable-logging[Enable client activity to a separate log file]'
'--force-http-1.1[Force the use of HTTP 1.1 for all operations]'
'--get-O365-drive-id[Query and return the Office 365 Drive ID for a given Office 365 SharePoint Shared Library]:'
'--local-first[Synchronize from the local directory source first, before downloading changes from OneDrive.]'
'--logout[Logout the current user]'
'(-m --monitor)'{-m,--monitor}'[Keep monitoring for local and remote changes]'
'--no-remote-delete[Do not delete local file deletes from OneDrive when using --upload-only]'
'--print-token[Print the access token, useful for debugging]'
'--resync[Forget the last saved state, perform a full sync]'
'--remove-directory[Remove a directory on OneDrive - no sync will be performed.]:directory name:'
'--single-directory[Specify a single local directory within the OneDrive root to sync.]:source directory:_files -/'
'--skip-dot-files[Skip dot files and folders from syncing]'
'--skip-symlinks[Skip syncing of symlinks]'
'--source-directory[Source directory to rename or move on OneDrive - no sync will be performed.]:source directory:'
'--syncdir[Specify the local directory used for synchronization to OneDrive]:sync directory:_files -/'
'--synchronize[Perform a synchronization]'
'--upload-only[Only upload to OneDrive, do not sync changes from OneDrive locally]'
'(-v --verbose)'{-v,--verbose}'[Print more details, useful for debugging (repeat for extra debugging)]'
'--version[Print the version and exit]'
'(-h --help)'{-h,--help}'[Print help information]'
)

_arguments -S "$all_opts[@]" && return 0