The Wayback Machine - https://web.archive.org/web/20201015064028/https://github.com/hluk/CopyQ/pull/1460
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 bash completion script #1460

Open
wants to merge 1 commit into
base: master
from

Conversation

@LiteracyFanatic
Copy link

@LiteracyFanatic LiteracyFanatic commented Aug 19, 2020

This is a work in progress which could definitely use a refactoring, but I thought I'd submit it for feedback since I have it in a functional state. It would be great if other people could test it on their systems to make sure it works properly. Just run source utils/copyq-completion from a bash shell. The type copyq and press tab.

There are comments explaining why some of the commands don't have completions, but I'll reiterate my questions here for clarity.

  1. Do we want any sort of completion for mime types? Obviously there are a great many of them, but perhaps there is some useful subset that would make sense to list. For clipboard, selection, and read in particular I wonder if there is a way to query the available mime types for the current data. That would be nice for discoverability.
  2. It would be possible to generate row numbers for the commands which take them, but since there would likely be a bunch of them this probably isn't a great idea.
  3. Would the acceptable values of the PROGRAM argument to action be any executable on the PATH?
  4. Is there an easy way to generate a list of allowed values for the config options that are finite sets i.e. booleans, enums, magic strings? It'd be nice to have, but I wouldn't want to hardcode it.
  5. What are sessions? How would I get a list of available sessions?
  6. Which commands are allowed as arguments to tab?
  7. Is utils/ the correct place for this script to live, or does it belong elsewhere?
@hluk
Copy link
Owner

@hluk hluk commented Aug 22, 2020

Nice! Notes below.

How command line works is explained in Scripting API reference. There are more functions you can use than those listed in --help (it lists only the most important). Some examples:

copyq iconColor red
copyq iconTag 123
copyq exportTab default_tab.cpq
copyq screenshot > screenshot.png

If there is fixed number of function arguments you can chain multiple functions:

copyq iconColor red sleep 1000 iconColor ''

You can usually list available media types (MIME) using ? argument:

copyq clipboard '?'
copyq read '?' 0

Probably the most important types can be listed with:

copyq clipboardFormatsToSave

The PROGRAM argument in action is any command:

copyq action 'copyq popup TEST'
copyq action "ls $HOME/Downloads"

You can list the configuration keys with copyq config but not the possible values.

Sessions are used to start separate application instances. The default session is empty string, i.e. copyq show is same as copyq -s '' show.

This is more of an implementation detail, but to get list of running sessions, you could do:

ss -l -x | sed -n '/\/\.copyq[^_]*_s /{s/.*\/\.copyq-\?\([^_]*\)_s .*/\1/;p}'

# ... or "find" instead of "ss" (but it's less reliable since the config dir can be anywhere)
find ~/.config/copyq* -type s

This is how you can use the tab argument:

# read the first three items in "work" tab, separated by comma
copyq tab work separator , read 0 1 2

Completion script could go to shared/ (CMake files would need to be updated to install the file).

BTW, most of the functions need a CopyQ server to be running, except help, info, version and logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.