5 ms·
Fish is really great for using it in your terminal. Autocompletion, fuzzy matching, and so on, are amazing. Unfortunately, although it is fully scriptable, wri
by dllu 9y ago
Fish is really great for using it in your terminal. Autocompletion, fuzzy matching, and so on, are amazing.
Unfortunately, although it is fully scriptable, writing scripts in Fish feels a little clunky at times. For example, I wanted to test if $dest exists, and if not, whether $src is newer than $dest. Since there are no && or ||, parentheses are used for command substitution, and the Fish version of "test" has no -nt to check if a file is newer, I have to do this:
if begin; not command test -f $dest; end; or begin; command test $src -nt $dest; end
# do something
end
- EpicEng 9y agoYeah, wow... I would have to spend at least 15 minutes figuring out what that does.
- zackelan 9y agoI'm a very happy fish user but this is one of my pain points as well. If you want to define a function, the syntax is light-years ahead of bash, including named arguments (and closures!), but it took a fair bit of googling and eyebrow-wrinkling before I could figure out the way just to set a default argument for that function. What I ended up with was (for a shortcut for generating a password on the command line): function pw --argument length test -z $length; and set length 16 python3.6 -c "import secrets; print(secrets.token_urlsafe($length))" end
- yorwba 9y agoWhen I last needed something similar, I wrote it like not command test -f $dest if or command test $src -nt $dest # do something end It saves on the begin ... end, but is confusing to look at. Nested conditions are really not very ergonomic in fish.
- ridiculous_fish 9y agoIt's true fish is generally more verbose, as it has less magical syntax. fish is also missing some niceties like `set -e` and `set -x` which we would like to add, but the main focus is interactive use. Happily the begin/ends in ifs are no longer necessary: if not command test -f $dest or command test $src -nt $dest # stuff end In this particular case, you can simplify it further with test's operators: if command [ ! -f $dest -o $src -nt $dest ] #stuff end which is comparable in length to bash, though other cases will certainly be longer.
- nyolfen 9y agouse ; in place of &&
- Rebelgecko 9y agoI think you should actually use "; and" in place of &&. That said I still wish fish support && and ||, if only for the times when I copy and paste some one-liner off of stack overflow and have to rewrite it.