Repository navigation
Open
Labels
Milestone
Description
The following functions/completions use sed etc in some way that may be able to be sensibly replaced by fish builtins such as string. Opening this issue so can track which ones have been completed.
sed:
- completions/abook.fish (eba099b)
- completions/apropos.fish (69afb1b)
- completions/bundle.fish
- completions/emerge.fish
- completions/eselect.fish
- completions/highlight.fish
- completions/killall.fish
- completions/mplayer.fish
- completions/mvn.fish
- completions/netctl.fish
- completions/open.fish (b1bbb58)
- completions/pactl.fish
- completions/perl.fish
- completions/setxkbmap.fish
- completions/ssh.fish
- completions/vared.fish (7d89cad)
- functions/__fish_complete_gpg_key_id.fish
- functions/__fish_make_completion_signals.fish
- functions/__fish_print_modules.fish
- functions/__fish_print_packages.fish
- functions/__fish_pwd.fish
- functions/fish_svn_prompt.fish
awk:
- completions/adb.fish
- completions/cwebp.fish
- completions/ezjail-admin.fish
- completions/find.fish
- completions/grunt.fish
- completions/helm.fish
- completions/heroku.fish
- completions/lsusb.fish
- completions/make.fish
- completions/p4.fish
- completions/psql.fish
- completions/rmmod.fish (6004d04)
- completions/vim-addons.fish
- functions/__fish_complete_convert_options.fish
- functions/__fish_complete_man.fish
- functions/__fish_describe_command.fish
- functions/__fish_print_addresses.fish
- functions/__fish_print_packages.fish
tr:
- completions/aura.fish
- completions/grunt.fish
- completions/pactree.fish
- completions/pkgfile.fish
- completions/rfkill.fish
- completions/rsync.fish
- functions/__fish_make_completion_signals.fish
- functions/__fish_parse_configure.fish
- functions/__fish_print_packages.fish
- functions/__fish_print_xdg_desktop_file_ids.fish
- functions/fish_svn_prompt.fish
echo $xx | string (can replace with string -- $xx):
- completions/j.fish
- completions/unzip.fish
cat:
- completions/gradle.fish (0de217d)
- completions/zypper.fish
- functions/__fish_complete_ant_targets.fish
- functions/__fish_parse_configure.fish
- functions/__fish_portage_print_repository_names.fish
- functions/__fish_portage_print_repository_paths.fish
- functions/__fish_print_packages.fish
- functions/__fish_print_xdg_mimetypes.fish
- functions/psub.fish
tail:
- completions/cargo.fish (9bf5dfd)
- completions/ezjail-admin.fish
- completions/kcmshell5.fish
- completions/phpunit.fish
- functions/__fish_complete_pids.fish
- functions/__fish_print_packages.fish
head:
- completions/apt.fish
- completions/j.fish
- completions/ssh.fish
- completions/zpool.fish
- functions/__fish_complete_zfs_rw_properties.fish
- functions/fish_npm_helper.fish
grep:
- completions/tokei.fish (30459b0)
cut:
- completions/amixer.fish (30459b0)
- completions/bat.fish (f036d01)
- completions/fossil.fish
- completions/fuser.fish (30459b0)
- completions/journalctl.fish (30459b0)
- completions/kill.fish (c1140bc)
- completions/machinectl.fish
- completions/modprobe.fish
- completions/pactree.fish
- completions/pkgfile.fish
- completions/svn.fish (30459b0)
- completions/tokei.fish (30459b0)
- completions/useradd.fish (30459b0)
- completions/xprop.fish
- functions/__fish_complete_groups.fish
- functions/__fish_complete_gpg_user_id.fish
- functions/__fish_complete_users.fish (4943ab6)
- functions/__fish_crux_packages.fish
- functions/__fish_is_zfs_feature_enabled.fish
- functions/__fish_print_packages.fish
- functions/__fish_systemctl_services.fish
- functions/fish_svn_prompt.fish
- functions/help.fish (eaf313f)
The following will not be implemented for now
test -n (replace with string length -q). (see here):
- share/config.fish
- share/functions/psub.fish
- tests/test_util.fish
- share/functions/__fish_config_interactive.fish
- share/functions/vared.fish
- share/functions/__fish_abbr_old.fish
- share/functions/__fish_cancel_commandline.fish
- share/functions/_fish_systemctl.fish
- share/functions/__fish_complete_man.fish
- share/functions/fish_clipboard_paste.fish
- share/functions/help.fish
- share/functions/history.fish
- share/functions/fish_clipboard_copy.fish
- share/functions/__fish_whatis_current_token.fish
- share/functions/fish_git_prompt.fish
- share/functions/umask.fish
- share/functions/__fish_print_hostnames.fish
- share/functions/__fish_not_contain_opt.fish
- share/functions/pushd.fish
- share/completions/sudo.fish
- share/functions/__fish_print_help.fish
- share/functions/__fish_contains_opt.fish
- share/completions/virsh.fish
- share/completions/pacman.fish
- share/functions/trap.fish
- share/completions/df.fish
- share/completions/doas.fish
- share/completions/p4.fish
- share/completions/aura.fish
- share/completions/dconf.fish
- share/completions/sed.fish
- share/completions/yaourt.fish
- share/completions/pacaur.fish
- share/completions/tar.fish
- share/completions/adb.fish
- share/completions/magento.fish
- share/completions/env.fish
- tests/checks/complete.fish
- share/tools/web_config/sample_prompts/robbyrussell.fish
- share/tools/web_config/sample_prompts/nim.fish
- share/tools/web_config/sample_prompts/debian_chroot.fish
- share/tools/web_config/sample_prompts/sorin.fish
Activity
[-]Stringify functions/completions[/-][+]fishify functions/completions[/+]faho commentedon Jan 22, 2020
Note that sometimes it might make sense to keep the external tools - e.g. in some cases awk is so fast you might think it was trying to stop Dr Eggman.
It also makes sense to show that
grepet al work in fish in the tutorial. Most people will also keep on using them in most cases, and that's okay.I mainly see two uses for using our builtins (given that we're already dog-fooding plenty):
In some cases it's faster than spinning up an external process (tho this advantage has gotten quite a bit smaller with us getting faster at doing that)
Increasing portability - some systems have e.g.
sedimplementations that suck, so being able to use a tool we control is a boonmqudsi commentedon Feb 2, 2020
The reason why I intentionally still use
sedandgrepin some fish scripts: they don't buffer (the entire content, at any rate). Until buffering is fixed, we should be very careful when replacing these withstringequivalents.6A61736F6E206E61646572 commentedon Feb 2, 2020
@mqudsi For educational purposes, do you have a (contrived) example for the above situations where sed/grep would be better suited?
krobelus commentedon Feb 3, 2020
The buffering matters when you process a sizeable amount of data (megabytes).
Compared to their string equivalent, awk or perl make this example from tshark.fish almost three times faster, probably because of buffering.
6A61736F6E206E61646572 commentedon Feb 3, 2020
Thanks. I was just wondering how often one would come across a situation like that in our completion/etc fish scripts.
mqudsi commentedon Feb 3, 2020
It would be a big deal if we ever got async completions, but I'm not sure which is further off (proper simultaneous execution of piped contexts or async reporting of available completions).
But there is a considerable amount of cases where buffering artificially constrains even non-interactive processes. For example, just yesterday I wanted to pipe the (reversed) output of a 68 GiB "since the start of time" log file, perform a manipulation on each line, then select the most recent n events predicated on the value of the manipulated line - this is something that could (and does) often come up in writing completions; here's what my case looked like:
The length of
/var/log/foo.logshould not matter, as I want to stop after 20 matches. But with buffering, fish needs to process the entirety of the log file and only then does it pass anything along tohead, which only uses the smallest sliver of whatstringgenerated.The only way to do this in fish (aside from creating and using a pipe then running the commands in the background) would have been to replace the no-brainer one-liner above with an actual "script" that read a line at a time, processed each line, incremented a counter, and then bailed when the desired count was reached.
faho commentedon Feb 3, 2020
Sure. If you're piping gigabytes.
However, I wouldn't overstate how often this happens, or how important this is.
E.g. @krobelus example has 204000 lines. Put a
head -n 10000in there, and the difference all but disappears. Most completions deal with much smaller data sets.Also that's with perl or awk. Try sed instead and we're much faster.
Please use our tools by default, unless you have a good reason (yes, performance counts) not to, and in that case please make it work according to the standard, so it works everywhere.
mqudsi commentedon Feb 3, 2020
Which is great, unless you want to limit based off the final count after manipulation rather than before.
But, yes. Definitely prefer
stringwhere it's an option.Mazorius commentedon Apr 6, 2020
With the following PR I improved gradle completion: #6864
This also removes usage of cat, echo and more.
Nahor commentedon Aug 4, 2026
Late to the discussion but:
process creation is really slow on Cygwin/MSYS2 (notably because they have to emulate
fork()):so avoiding using external commands on MSYS2 would be a significant benefit in most scenarios, especially when things need to be fast (completion, prompt).
For comparision, in WSL:
@krobelus example is in favor of
stringon my machine under MSYS2but then also I get this:
so there may be some issues with using
tsharkitself and it may not be the best example to use in the first place.