Skip to content

Instantly share code, notes, and snippets.

@smblott-github
Last active March 16, 2018 03:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smblott-github/22e6222c81ecd8dc0771 to your computer and use it in GitHub Desktop.
Save smblott-github/22e6222c81ecd8dc0771 to your computer and use it in GitHub Desktop.
Simple zsh completion for insync, insync-headless and insync-portable. Grab this, name it "_insync-headless" and put it in some suitable location for zsh completion functions. And good luck. Zsh completion is a mystery to me.
#compdef insync-headless insync-portable insync
if [[ $CURRENT == 2 ]]
then
_values 'commands' \
'accept_all_new_shares[Accept all new shares file to given account]' \
'accept_share[Accept shared file to given account]' \
'add_account[Add account to Insync]' \
'force_sync[Force sync item]' \
'get_account_information[Show information for connected acounts]' \
'get_actions_required[Show required actions]' \
'get_domain_link[Get domain link for file]' \
'get_errors[Show error messages]' \
'get_file_status[Get syncing status of file]' \
'get_new_shares[Show new shares]' \
'get_private_link[Get private link for file]' \
'get_proxy[Show proxy configuration]' \
'get_public_link[Get public link for file]' \' \
'get_recent_changes[20 most recent changes]' \
'get_root_drive_files[Get selective sync information for root Drive files and folders of account]' \
'get_status[Show syncing status]' \
'get_sync_progress[Show progress of files being downloaded/uploaded]' \
'manage_selective_sync[Manage selective sync settings of account]' \
'move_folder[Move folder to a new path]' \
'open_in_gdrive[Open selected file in Google Drive web interface]' \
'pause_syncing[Pause syncing]' \
'quit[Quit]' \
'reject_all_new_shares[Reject all new shares to given account]' \
'reject_share[Reject shared file to given account]' \
'remove_account[Remove account from Insync]' \
'remove_from_insync[Remove linked file/folder from Insync]' \
'resume_syncing[Resume syncing]' \
'retry_errors[Retry all errors]' \
'set_autostart[Set autostart preference (yes/no)]' \
'set_export_option[Download Google Docs files as docs or links]' \
'set_proxy[Set proxy config]' \
'set_selective_sync[Set selective sync preference (yes/no) of file for given email]' \
'share[Share selected file using Insync web interface]' \
'start[Start Insync]'
return
fi
# we are completing the second or a subsequent argument.
local insync='insync'
which $insync > /dev/null || insync='insync-headless'
which $insync > /dev/null || insync='insync-portable'
if ! which $insync > /dev/null
then
# Provide some kind of (possibly useless) default.
_path_files
return
fi
__insync_get_all_emails ()
{
local -a accounts
accounts=( $( $insync get_account_information 2> /dev/null | grep -E -o "\<[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\>" ) )
(( 0 < $#accounts )) && _values "accounts" $accounts
}
if (( 2 < $CURRENT ))
then
case $words[2] in
'get_root_drive_files' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails ;;
'remove_account' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails ;;
'manage_selective_sync' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails ;;
'accept_all_new_shares' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails ;;
'reject_all_new_shares' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails ;;
'accept_share' ) [[ $CURRENT == 4 ]] && __insync_get_all_emails ;;
'reject_share' ) [[ $CURRENT == 4 ]] && __insync_get_all_emails ;;
'add_account' ) [[ $CURRENT == 4 ]] && _path_files -/ ;;
'force_sync' ) [[ $CURRENT == 3 ]] && _path_files -/ ;;
'get_file_status' ) [[ $CURRENT == 3 ]] && _path_files -f ;;
'get_private_link' ) [[ $CURRENT == 3 ]] && _path_files -f ;;
'get_public_link' ) [[ $CURRENT == 3 ]] && _path_files -f ;;
'open_in_gdrive' ) [[ $CURRENT == 3 ]] && _path_files -f ;;
'share' ) [[ $CURRENT == 3 ]] && _path_files -f ;;
'remove_from_insync' ) [[ $CURRENT == 3 ]] && _path_files ;;
'get_domain_link' ) [[ $CURRENT == 3 ]] && _path_files ;;
'set_autostart' ) [[ $CURRENT == 3 ]] && _values "autostart" "yes" "no" ;;
'set_selective_sync' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails
[[ $CURRENT == 5 ]] && _values "selective sync" "yes" "no" ;;
'move_folder' ) [[ $CURRENT == 3 ]] && _path_files -/
[[ $CURRENT == 4 ]] && _path_files -/ ;;
'set_export_option' ) [[ $CURRENT == 3 ]] && __insync_get_all_emails
[[ $CURRENT == 4 ]] && _values "document export format" "office" "link" ;;
esac
fi
@yochaigal
Copy link

yochaigal commented Mar 16, 2018

For anyone wondering where to put this, create the file in a folder (like ~/..zsh) and then add this to your ~/.zshrc file:
fpath=(~/.zsh/ $fpath)

So that it gets picked up. Make sure it begins with an underscore!

Thanks for making this, btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment