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

New completions: figlet, mdbook, ranger, pygmentize + xz fix #3378

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions share/completions/figlet.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function __fish_print_figlet_fonts
find (figlet -I2) -type f ^ /dev/null | sed -e 's$/.*/\([^/.]*\)\.[ft]lf$\1\tFont$;tx;d;:x'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does figlet -I2 output?

This might be nicer with string, though it's something we can also do later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> figlet -I2
/usr/share/figlet/fonts
> find (figlet -I2) -type -f ^ /dev/null
/usr/share/figlet/fonts/slant.flf
/usr/share/figlet/fonts/ilhebrew.flc
/usr/share/figlet/fonts/banner.flf
/usr/share/figlet/fonts/646-jp.flc
/usr/share/figlet/fonts/646-irv.flc
/usr/share/figlet/fonts/646-es.flc
/usr/share/figlet/fonts/8859-4.flc
/usr/share/figlet/fonts/646-cn.flc
/usr/share/figlet/fonts/646-fr.flc
/usr/share/figlet/fonts/standard.flf
/usr/share/figlet/fonts/646-pt.flc
/usr/share/figlet/fonts/ivrit.flf
/usr/share/figlet/fonts/hz.flc
... and some more ...

We only want the name of the fonts (files with the extension .flf or .tlf). Here, that would be:

slant
banner
standard
... and some more ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does the same thing:

function __fish_print_figlet_fonts
    set -l lines (find (figlet -I 2) -type f | string match -r '/.*/(.*)\.[ft]lc')

    while set -q lines[2]
        printf '%s\tFont\n' $lines[2]
        set -e lines[1]
        set -e lines[1]
    end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

set -l dir (figlet -I 2)
set -l files $dir/*.flf $dir/*.tlf

printf '%s\tFont\n' (string replace -r '.*/([^/]+)\.[ft]lf' '$1' -- $files)

?

You might want to test the performance here. To do that, define the function, execute it and echo $CMD_DURATION right after. That'll give you the time in milliseconds.

Copy link
Contributor Author

@moverest moverest Sep 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution is much faster (yours: 4ms; sed: 12ms; find + match: 25ms). I'll commit it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my intuition was correct. The trick, and this applies to all shells, is to use builtins unless you're dealing with large datasets, when specialized tools (GNU's grep is blindlingly fast) might make sense. There's a constant cost to forking off an external command.

end

complete -c figlet -s f -d "Select font" -x -a "(__fish_print_figlet_fonts)"
complete -c figlet -s d -d "Change font directory"
complete -c figlet -s c -d "Center output horizontally"
complete -c figlet -s l -d "Make output flush-left"
complete -c figlet -s r -d "Make output flush-right"
complete -c figlet -s x -d "Set justification according to text direction"
complete -c figlet -s t -d "Set output to terminal width"
complete -c figlet -s w -d "Set output width"
complete -c figlet -s p -d "Put FIGlet into `paragraph mode`"
complete -c figlet -s n -d "Put FIGlet back to normal"
complete -c figlet -s D -d "Switch to German (ISO 646-DE) character set"
complete -c figlet -s E -d "Turns off German character set processing"
complete -c figlet -s C -d "Add given control file" -a "(__fish_complete_suffix .flc)" -x
complete -c figlet -s N -d "Clear control file list"
complete -c figlet -s s -d "Cause `smushing`"
complete -c figlet -s S -d "Cause `smushing`"
complete -c figlet -s k -d "Cause `kerning`"
complete -c figlet -s W -d "Makes FIGlet all FIGcharacters at full width"
complete -c figlet -s o -d "Cause `overlapped`"
complete -c figlet -s m -d "Specify layout mode between 1 and 63"
complete -c figlet -s v -d "Print version and copyright"
complete -c figlet -s I -d "Print information given infocode" -x -a "0\tVersion\ and\ copyright 1\tVersion\ \(integer\) 2\tDefault\ font\ directory 3\tFont 4\tOutput\ width 5\tSupported\ font\ format"
complete -c figlet -s L -d "Print left-to-right"
complete -c figlet -s R -d "Print right-to-left"
complete -c figlet -s X -d "Print with default text direction"
19 changes: 19 additions & 0 deletions share/completions/mdbook.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -l cmds build help init serve test watch

complete -c mdbook -f
complete -c mdbook -s l -l help -d "Prints help"
complete -c mdbook -s V -l version -d "Prints version"

complete -c mdbook -n "not __fish_seen_subcommand_from $cmds" -a build -d "Build book from markdown files"
complete -c mdbook -n "not __fish_seen_subcommand_from $cmds" -a help -d "Prints help"

complete -c mdbook -n "not __fish_seen_subcommand_from $cmds" -a init -d "Create boilerplate structure and files in directory"
complete -c mdbook -n "__fish_seen_subcommand_from init" -l force -d "Skip confirmation prompts"
complete -c mdbook -n "__fish_seen_subcommand_from init" -l theme -d "Copy default theme into source folder"

complete -c mdbook -n "not __fish_seen_subcommand_from $cmds" -a serve -d "Serve book at http://localhost:3000"
complete -c mdbook -n "__fish_seen_subcommand_from serve" -l port -s p -x -d "Use another port (default 3000)"
complete -c mdbook -n "__fish_seen_subcommand_from serve" -l websocket-port -s w -x -d "Use another port for websocket (default 3001)"

complete -c mdbook -n "not __fish_seen_subcommand_from $cmds" -a test -d "Test that code samples compile"
complete -c mdbook -n "not __fish_seen_subcommand_from $cmds" -a watch -d "Watch file changes"
30 changes: 30 additions & 0 deletions share/completions/pygmentize.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function __fish_print_pygmentize --argument-names type description
for line in (pygmentize -L $type | sed -e "s%^\* \(.*\):%\1%;tx;d;:x" | string split ", ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any example output here? We might be able to use string instead of sed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> pygmentize -L filters
Pygments version 2.1.3, (c) 2006-2015 by Georg Brandl.

Filters:
--------
* gobble:
    Gobbles source code lines (eats initial characters).
* highlight:
    Highlight a normal Name (and Name.*) token with a different token type.
* tokenmerge:
    Merges consecutive tokens with the same token type in the output stream of a lexer.
* raiseonerror:
    Raise an exception when the lexer generates an error token.
* codetagify:
    Highlight special code tags in comments and docstrings.
* whitespace:
    Convert tabs, newlines and/or spaces to visible characters.
* keywordcase:
    Convert keywords to lowercase or uppercase or capitalize them, which means first letter uppercase, rest lowercase.

What it does is that it selects all lines that match the regex (lines beginning with * and containing a :) and extracts the names while discarding every lines that haven't been matched.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> pygmentize -L filters | string match -r "\* (.*):"
* raiseonerror:
raiseonerror
* gobble:
gobble
* whitespace:
whitespace
* highlight:
highlight
* tokenmerge:
tokenmerge
* codetagify:
codetagify
* keywordcase:
keywordcase

It returns what I want and the entire line. I don't know how to get rid of it (without doing something horrible). :-/

Copy link
Member

@faho faho Sep 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's easy - string match -r '^\* \S+:' | string replace -r '^\* (\S+):' '$1'. This would be another case where a "only-matching" option would be useful.

In this case, we can probably save that to a variable and use the following line as description.

Try this:

set -l lines (pygmentize -L $type | string match -r '^(?:\* |    ).*(?:)$' | string replace -r '\* (.*):$' '$1' | string trim)

while set -q lines[2]
    printf '%s\t%s\n' $lines[1] $lines[2]
    set -e lines[1]
    set -e lines[1]
end

printf "%s\t%s\n" $line $description
end
end

complete -c pygmentize -s o -d "Set output file"
complete -c pygmentize -s s -d "Read one line at a time"
complete -c pygmentize -s l -d "Set lexer" -x -a "(__fish_print_pygmentize lexers Lexer)"
complete -c pygmentize -s g -d "Guess lexer"
complete -c pygmentize -s f -d "Set formater" -x -a "(__fish_print_pygmentize formaters Formater)"
complete -c pygmentize -s O -d "Set coma-seperated options" -x
complete -c pygmentize -s P -d "Set one option" -x
complete -c pygmentize -s F -d "Set filter" -x -a "(__fish_print_pygmentize filters Filter)"
complete -c pygmentize -s S -d "Print style definition for given style" -x -a "(__fish_print_pygmentize styles Style)"
complete -c pygmentize -s L -d "List lexers, formaters, styles or filters" -x -a "lexers formaters styles filters"
complete -c pygmentize -s N -d "Guess and print lexer name based on given file"
complete -c pygmentize -s H -d "Print detailed help" -x -a "lexer formatter filter"
complete -c pygmentize -s v -d "Print detailed traceback on unhandled exceptions"
complete -c pygmentize -s h -d "Print help"
complete -c pygmentize -s V -d "Print package version"

function __test_args
echo ... >> /tmp/args
__fish_print_cmd_args >> /tmp/args
return 1
end

complete -n "__test_args" -d Hello
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you didn't want to include this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed...


14 changes: 14 additions & 0 deletions share/completions/ranger.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
complete -c ranger -s d -l debug -d "Activate debug mode"
complete -c ranger -s c -l clean -d "Activate clean mode"
complete -c ranger -s r -l confdir -d "Change configuration directory"
complete -c ranger -l copy-config -x -d "Create copies of the default configuration" -a "all commands commands_full rc rifle scope"
complete -c ranger -l chosefile -r -d "Pick file with ranger"
complete -c ranger -l chosefiles -r -d "Pick multiple files with ranger"
complete -c ranger -l chosedir -r -d "Pick directory"
complete -c ranger -l selectfile -r -d "Open ranger with given file selected"
complete -c ranger -l list-unused-keys -d "List common keys which are not bound"
complete -c ranger -l list-tagged-files -f -d "List all tagged files with given tag (default *)"
complete -c ranger -l profile -d "Print statistics of CPU usage on exit"
complete -c ranger -l cmd -r -d "Execute command after configuration file read"
complete -c ranger -l version -d "Print version"
complete -c ranger -l help -s h -d "Print help"
2 changes: 1 addition & 1 deletion share/completions/xz.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
complete -c xz -s z -l compress --description 'Compress'
complete -c xz -s d -l decompress -l uncompress --description 'Decompress' -a "
complete -c xz -s d -l decompress -l uncompress --description 'Decompress' -x -a "
(
__fish_complete_suffix .xz
__fish_complete_suffix .txz
Expand Down