5 ms·
Shells and scripting languages are different things. I don't care how good of a scripting language Powershell is, it's painful to use as a shell. I don't care t
by thrwyoilarticle 5y ago
Shells and scripting languages are different things. I don't care how good of a scripting language Powershell is, it's painful to use as a shell. I don't care that fish can't run sh scripts, I've never used it on a machine that didn't have sh. Can we stop judging oranges for their lack of crunch?
- smoldesu 5y agoYeah, I hear a lot of people throw shade at fish and then act equally surprised when I don't run my scripts with it. Much like Bash, Perl, Python or even ZSH by some respects, fish is just another tool in my toolbox. It so happens to be the one I default to though, which for some reason sends people flying off the handle.
- pxc 5y agoIdeally you do want them to be the same, so that the skill of using one reinforces the skill of using the other, and you can begin to shape scripts out of your shell history. Output redirection doesn't work right with Fish functions, which makes them unusable in certain kinds of scripts. Aside from that, though, Fish is perfectly pleasant for simple scripting. I use Fish for simple stuff and PowerShell for anything serious. Some day I'd like to use something like Elvish or Nushell for both, and use the same language as my interactive shell.
- buu700 5y agoAgreed. I liked fish last time I tried it (probably over a decade ago), but bash scripting is what I'm familiar with and it's just so convenient in day-to-day usage to be able to throw out one-liners for mundane things and then have them permanently searchable in my history.
- yourad_io 5y agoI thought Ctrl+R was cool but in fish you are always in search mode! Start typing any part of your previous command and hit up arrow!
- aembleton 5y agoHave you just tried the following to run your bash one liners in fish? bash -c 'echo "hello"' Replacing echo "hello" with your script.
- buu700 5y agoYou could do that, but it would be pretty inconvenient in general, and more so when using quotes within the script. There would also be no autocomplete.
- deleted 5y ago[deleted]
- pxc 5y agoSo I don't think this quite solves the issue you describe, which is that if your history was full of convenient Fish one-liners, you wouldn't be able to reuse them in your scripts, because for scripting you prefer Bash. But: 1. I have CTRL+R bound to fuzzy reverse history search via fzf in my Fish config. It works great. It's fast, and it's way better than the built-in Bash reverse history search imo, even though it works basically the same way (it should feel very familiar). fzf itself comes with the keybindings, so you don't have to sort them out yourself; you can just source 'em: https://github.com/junegunn/fzf/blob/master/shell/key-bindings.fish https://github.com/junegunn/fzf/blob/master/shell/key-bindin... 2. For one-off one liners you see in GitHub repos or something, if you really want tab completion and syntax highlighting and whatever, you can just use `exec` twice: ⋊> ~ echo $HELLO ⋊> ~ exec bash ~ $ export HELLO=hello ~ $ exec fish Welcome to fish, the friendly interactive shell ⋊> ~ echo $HELLO hello 3. If you want to import your handy one-liners from your existing `.bash_history`, you could try using babelfish to automatically translate them, then import them into your Fish history: https://github.com/bouk/babelfish https://github.com/bouk/babelfish It may not work right for some of them, but it's worked on the scripts I've tried. You might also be able to bind a key that translates whatever command there is on the prompt into Fish. It seems to handle the basics well, including subshells with redirection/process substitution, e.g.: ~ $ cat <(echo hi) hi ~ $ history | sed -E 's/^[[:space:]]+[[:digit:]]+[[:space:]]+//g' | grep -E '^cat' | tail -n1 | babelfish cat (echo hi | psub) ~ $ fish Welcome to fish, the friendly interactive shell ⋊> ~ cat (echo hi | psub) hi ⋊> ~ exit ~ $ Babelfish is pretty fast. Maybe you could create a Fish keybind that searches through your bash history, only it's translated to Fish via babelfish? Then at least you could keep your existing history in a way :D
- kaba0 5y agoBash scripting and convenient is strange in the same sentence. Bash is an abomination that should not even exist. Like, even thinking about a line of bash code will have 3 bugs.
- MaulingMonkey 5y ago> Ideally you do want them to be the same, so that the skill of using one reinforces the skill of using the other, I've used several dozen shells, script languages, and programming languages - and have needed to do within the context of a single job. What's one more? For an interactive shell I prioritize writeability, and for scripts I prioritize readability and maintainability. These are often at odds - not just in what I write, but in the syntax itself - and by making my shell and script the same, I make middling compromises resulting in a jack of all trades that is a master of none. I disagree that this is "ideal". > and you can begin to shape scripts out of your shell history. It's been my experience that this is quite doable even when the scripting language has different syntax than your shell. Oh, sure, it's not as simple as Copy+Paste - but it's never that simple. Even simple shell scripts inevitably end up needing error checking, sanity checks, error messages, ...
- ChrisSD 5y agoEh. Tbh I'm find both powershell and unixy shells have their advantages and warts. I'm not sure either is "better". Maybe I'm just not a fan of shells in general.
- emersion 5y agoIt's pretty common to copy-paste POSIX sh one-liners, or `source` a simple script. fish makes this annoying to do.
- shepherdjerred 5y agoI’ll trade the occasional minor annoyance for the day-to-day ease of use that fish provides
- KptMarchewa 5y agobash -c "PASTE_HERE"
- adrusi 5y agoThat's annoying when you have complex quoting in the pasted script, but you can always do bash PASTE_HERE exit Works for everything unless the pasted commands set variables you want to use.
- CGamesPlay 5y agoActually, in the last few years this gripe has gone away, at least for me. Once they added proper support for `VAR=val cmd && othercmd`, I haven't run across any one-liners that didn't work in fish.
- joshmanders 5y agoThe only issue I ran into this was when the one liners had subshell syntax $(cmd here), and all I had to do was convert $() to just ().
- mattgreenrocks 5y agoAFAIK that will be remedied in an upcoming release.
- ryenus 5y agoIndeed, the following should work with upcoming fish 3.4: echo "pwd: $(pwd)" See https://github.com/fish-shell/fish-shell/pull/8059 https://github.com/fish-shell/fish-shell/pull/8059
- deleted 5y ago[deleted]
- alerighi 5y agoBecause for you these are two distinct phases. But how many times you use a for loop for launching the same command multiple times? How many time you pass the output of the command as a parameter to another with $(command)? Or you use variable to save things? Beside very basic usage, a shell is really a REPL for a scripting language. You can type commands but also you can do most advanced things (and that is what makes shell powerful). For example I maybe have to convert all the video files in a directory, and then upload them to a server, I can easily do that with a for loop in the shell, without creating a script. And since you use both the shell to type commands and to write effectively scripts as in a REPL, that means that you have to learn another completely different programming language, the fish language (of course I assume that you already know POSIX scripting), and not only that, it's probably the case that only on your computer you have fish but it's not installed on every other system, so when you are using another computer (a server, a computer of a coworker that you are helping, etc) you will make mistakes because you confuse the fish syntax with the one of POSIX shell. Yes, it's true that bash extends POSIX, and zsh too and it's not even compatible 100% with bash, but the differences are in things that it's rare that you will use in a basic script, and all these shells can understand POSIX syntax. A for loop it's the same in sh, bash and zsh (there is a shorter syntax in zsh, but the base one is the same), while it's completely different in fish.