Skip to content

Commit

Permalink
Add --get-file-link option to shell completions (#2308)
Browse files Browse the repository at this point in the history
* Add --get-file-link option to bash completion
* Add --get-file-link completions for fish and zsh
* Have --get-file-link completion complete files in sync_dir

---------

Co-authored-by: abraunegg <alex.braunegg@gmail.com>
  • Loading branch information
jojhelfer and abraunegg authored Mar 6, 2023
1 parent eaeebbd commit 537b433
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions contrib/completions/complete.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _onedrive()
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 --download-only --disable-upload-validation --dry-run --enable-logging --force-http-1.1 --force-http-2 --local-first --logout -m --monitor --no-remote-delete --print-token --reauth --resync --skip-dot-files --skip-symlinks --synchronize --upload-only -v --verbose --version -h --help'
options='--check-for-nomount --check-for-nosync --debug-https --disable-notifications --display-config --display-sync-status --download-only --disable-upload-validation --dry-run --enable-logging --force-http-1.1 --force-http-2 --get-file-link --local-first --logout -m --monitor --no-remote-delete --print-token --reauth --resync --skip-dot-files --skip-symlinks --synchronize --upload-only -v --verbose --version -h --help'
argopts='--create-directory --get-O365-drive-id --operation-timeout --remove-directory --single-directory --source-directory'

# Loop on the arguments to manage conflicting options
Expand All @@ -19,12 +19,21 @@ _onedrive()
[[ ${COMP_WORDS[i]} == '--synchronize' ]] && options=${options/--monitor}
[[ ${COMP_WORDS[i]} == '--monitor' ]] && options=${options/--synchronize}
done

case "$prev" in
--confdir|--syncdir)
_filedir
return 0
;;

--get-file-link)
if command -v sed &> /dev/null; then
pushd "$(onedrive --display-config | sed -n "/sync_dir/s/.*= //p")" &> /dev/null
_filedir
popd &> /dev/null
fi
return 0
;;
--create-directory|--get-O365-drive-id|--operation-timeout|--remove-directory|--single-directory|--source-directory)
return 0
;;
Expand All @@ -33,7 +42,7 @@ _onedrive()
return 0
;;
esac

# notreached
return 0
}
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/complete.fish
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ complete -c onedrive -l dry-run -d 'Perform a trial sync with no changes made.'
complete -c onedrive -l enable-logging -d 'Enable client activity to a separate log file.'
complete -c onedrive -l force-http-1.1 -d 'Force the use of HTTP 1.1 for all operations.'
complete -c onedrive -l force-http-2 -d 'Force the use of HTTP 2 for all operations.'
complete -c onedrive -l get-file-link -d 'Display the file link of a synced file.'
complete -c onedrive -l get-O365-drive-id -d 'Query and return the Office 365 Drive ID for a given Office 365 SharePoint Shared Library.'
complete -c onedrive -s h -l help -d 'Print help information.'
complete -c onedrive -l local-first -d 'Synchronize from the local directory source first, before downloading changes from OneDrive.'
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/complete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ all_opts=(
'--enable-logging[Enable client activity to a separate log file]'
'--force-http-1.1[Force the use of HTTP 1.1 for all operations]'
'--force-http-2[Force the use of HTTP 2 for all operations]'
'--get-file-link[Display the file link of a synced file.]:file name:'
'--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]'
Expand Down

0 comments on commit 537b433

Please sign in to comment.