From 8e5156d01c3c7a940bb19a7497f40bb7a1574b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Tue, 15 Feb 2022 23:11:30 +0100 Subject: [PATCH] fish plugin: Add --output option --- beetsplug/fish.py | 29 +++++++++++++++++++++-------- docs/changelog.rst | 1 + docs/plugins/fish.rst | 3 +++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/beetsplug/fish.py b/beetsplug/fish.py index 21fd67f60..d0bedbedf 100644 --- a/beetsplug/fish.py +++ b/beetsplug/fish.py @@ -81,6 +81,11 @@ class FishPlugin(BeetsPlugin): choices=library.Item.all_keys() + library.Album.all_keys(), help='include specified field *values* in completions') + cmd.parser.add_option( + '-o', + '--output', + default=None, + help='save the script to a specific file, by default it will be saved to ~/.config/fish/completions') return [cmd] def run(self, lib, opts, args): @@ -89,14 +94,22 @@ class FishPlugin(BeetsPlugin): # If specified, also collect the values for these fields. # Make a giant string of all the above, formatted in a way that # allows Fish to do tab completion for the `beet` command. - home_dir = os.path.expanduser("~") - completion_dir = os.path.join(home_dir, '.config/fish/completions') - try: - os.makedirs(completion_dir) - except OSError: - if not os.path.isdir(completion_dir): - raise - completion_file_path = os.path.join(completion_dir, 'beet.fish') + + completion_file_path = opts.output + if completion_file_path is not None: + completion_dir = os.path.dirname(completion_file_path) + else: + home_dir = os.path.expanduser("~") + completion_dir = os.path.join(home_dir, '.config/fish/completions') + completion_file_path = os.path.join(completion_dir, 'beet.fish') + + if completion_dir != '': + try: + os.makedirs(completion_dir) + except OSError: + if not os.path.isdir(completion_dir): + raise + nobasicfields = opts.noFields # Do not complete for album/track fields extravalues = opts.extravalues # e.g., Also complete artists names beetcmds = sorted( diff --git a/docs/changelog.rst b/docs/changelog.rst index 2878c7953..523436bea 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -59,6 +59,7 @@ Other new things: * :doc:`/plugins/limit`: Limit query results to head or tail (``lslimit`` command only) +* :doc:`/plugins/fish`: Add ``--output`` option. 1.6.0 (November 27, 2021) ------------------------- diff --git a/docs/plugins/fish.rst b/docs/plugins/fish.rst index b2cb096ee..80dd3fb99 100644 --- a/docs/plugins/fish.rst +++ b/docs/plugins/fish.rst @@ -50,3 +50,6 @@ with care when specified fields contain a large number of values. Libraries with for example, very large numbers of genres/artists may result in higher memory utilization, completion latency, et cetera. This option is not meant to replace database queries altogether. + +By default the completion file will be generated at ``~/.config/fish/completions/``, +if you want to save it somewhere else you can use the ``-o`` or ``--output``.