Skip to content

Commit

Permalink
[beetsplug/fish] Eliminate unnecessary string concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
Arav K. committed Sep 8, 2024
1 parent 9f6ada4 commit 0ce8e1b
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions beetsplug/fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,13 @@ def run(self, lib, opts, args):
for name in names:
cmd_names_help.append((name, cmd.help))
# Concatenate the string
totstring = HEAD + "\n"
totstring = f"{HEAD}\n"
totstring += get_cmds_list([name[0] for name in cmd_names_help])
totstring += "" if nobasicfields else get_standard_fields(fields)
totstring += get_extravalues(lib, extravalues) if extravalues else ""
totstring += "\n" "# ====== setup basic beet completion =====" "\n\n"
totstring += "\n# ====== setup basic beet completion =====\n\n"
totstring += get_basic_beet_options()
totstring += (
"\n" "# ====== setup field completion for subcommands =====" "\n"
)
totstring += "\n# ====== setup field completion for subcommands =====\n"
totstring += get_subcommands(cmd_names_help, nobasicfields, extravalues)
# Set up completion for all the command options
totstring += get_all_commands(beetcmds)
Expand All @@ -149,17 +147,13 @@ def _escape(name):

def get_cmds_list(cmds_names):
# Make a list of all Beets core & plugin commands
substr = ""
substr += "set CMDS " + " ".join(cmds_names) + ("\n" * 2)
return substr
return f"set CMDS {' '.join(cmds_names)}\n\n"


def get_standard_fields(fields):
# Make a list of album/track fields and append with ':'
fields = (field + ":" for field in fields)
substr = ""
substr += "set FIELDS " + " ".join(fields) + ("\n" * 2)
return substr
fields = (f"{field}:" for field in fields)
return f"set FIELDS {' '.join(fields)}\n\n"


def get_extravalues(lib, extravalues):
Expand All @@ -168,14 +162,7 @@ def get_extravalues(lib, extravalues):
word = ""
values_set = get_set_of_values_for_field(lib, extravalues)
for fld in extravalues:
extraname = fld.upper() + "S"
word += (
"set "
+ extraname
+ " "
+ " ".join(sorted(values_set[fld]))
+ ("\n" * 2)
)
word += f"set {fld.upper()}S {' '.join(sorted(values_set[fld]))}\n\n"
return word


Expand Down Expand Up @@ -219,7 +206,7 @@ def get_subcommands(cmd_name_and_help, nobasicfields, extravalues):
for cmdname, cmdhelp in cmd_name_and_help:
cmdname = _escape(cmdname)

word += "\n" f"# ------ fieldsetups for {cmdname} -------" "\n"
word += f"\n# ------ fieldsetups for {cmdname} -------\n"
word += BL_NEED2.format(
("-a " + cmdname), ("-f " + "-d " + wrap(clean_whitespace(cmdhelp)))
)
Expand Down Expand Up @@ -256,8 +243,7 @@ def get_all_commands(beetcmds):
for name in names:
name = _escape(name)

word += "\n"
word += "\n\n" f"# ====== completions for {name} =====" "\n"
word += "\n\n\n# ====== completions for {name} =====\n"

for option in cmd.parser._get_all_options()[1:]:
cmd_l = (
Expand Down

0 comments on commit 0ce8e1b

Please sign in to comment.