Hot answers tagged

134

Fish doesn't have a special syntax for a logical AND (&&) or a logical OR (||). Instead, you can use the commands and and or, which verify the previous command's exit status and act accordingly: command1 and command2 command1 or command2 Furthermore – just like in bash – you can use a semicolon ; to execute two commands one after the other: ...


48

I've never used fish myself but a cursory google search brought up this page which states that Powerful History Mechanism Modern shells save previous commands in a command history. You can view earlier commands by using the up and down arrows. Fish extends this concept by integrating the history search functionality. To search the history, simply type in ...


41

TL;DR: Make sure RVM is up-to-date to at least 1.26.11 by re-installing or issuing the command rvm get head, and is only being initialized once per terminal environment. Result Eventually I was able to fix my environment. I will post some information pertaining to my specific problem in an effort to help some, even though others may have the same symptom ...


37

The 'fish' way of setting the $PATH variable is to actually use set --universal fish_user_paths $fish_user_paths /new/path/here. Then $fish_user_paths is actually prepended to the $PATH variable when a new session starts. The $PATH documentation doesn't currently tell you how to delete it though. In fish every variable is actually a list (array), and you ...


31

You can use Bash to parse /etc/profile and ~/.profile, and then start fish. Create /usr/local/bin/fishlogin with contents #!/bin/bash -l exec -l fish "$@" Make it executable sudo chmod +x /usr/local/bin/fishlogin Add it to /etc/shells echo /usr/local/bin/fishlogin | sudo tee -a /etc/shells Set it as your default shell sudo usermod -s /usr/local/bin/...


28

Alt-Up arrow gives you the last argument from the previous command. Subsequent pushes cycle throught prior arguments. I haven't found a satisfactory equivalent to !!, except Up then Ctrl-A


25

This is the canonical way to do so set -Ux EDITOR pico U for universal variable x to export it


23

fish shell 2.1.0 is now officially supported in Cygwin, it's possible to install it using the default installer.


23

If you're using oh my fish you can install the nvm plugin (after installing NVM with homebrew). $ omf install nvm Then set the NVM_DIR and all should be fine. $ set -gx NVM_DIR (brew --prefix nvm)


21

First thing to point out is that you can do this via tmux completely independent of your shell. Add the following to your ~/.tmux.conf; for example: set-option -g set-titles on set-option -g set-titles-string "#S / #W" Also, you need to ensure iTerm2 is configured to let programs set the title via an escape sequence. See the "Terminal may set tab/window ...


18

Unfortunately, the assumption that stderr is only used for error output isn't always correct. Rather, stderr is often used for any and all interactive output and diagnostics, i.e. output intended for the user to read in an interactive prompt1. wget and dd are well-known examples. Some commands will provide a flag (e.g. -quiet or -silent) to suppress non-...


17

In fish, $ is used only for variable expansion. Omit the $ from the command and you should be good. Say: ls -l (which vim) You might also want to refer to the documentation: Command Substitutions


16

For a much cleaner solution, you can use the foreign env plugin: fenv source ~/.profile


15

My current solution (see here for a maybe more recent version): egrep "^export " ~/.profile | while read e set var (echo $e | sed -E "s/^export ([A-Z_]+)=(.*)\$/\1/") set value (echo $e | sed -E "s/^export ([A-Z_]+)=(.*)\$/\2/") # remove surrounding quotes if existing set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/") if test $var = "...


13

The logical operators you're used to, are supported since fish 3.0.0, released on 2018-12-28. From the v3 release notes: fish now supports && (like and), || (like or), and ! (like not), for better migration from POSIX-compliant shells (#4620).


13

I found this perfect answer on the fish-users mailing list: function bind_bang switch (commandline -t)[-1] case "!" commandline -t $history[1]; commandline -f repaint case "*" commandline -i ! end end function bind_dollar switch (commandline -t)[-1] case "!" commandline -t "" ...


12

Unix utilities send general messages to stdout, and error messages to stderr, so if we only want to see error messages, then it will be sufficient to suppress stdout so only stderr gets output to the console. The way to do this (in both bash and fish) is to append >/dev/null to the command. This pipes stdout into nothingness, but stderr (with your error ...


12

Sorry, I'm not sure if I understand what you're asking. But if your question is how to set your abbr definitions on startup (and in a file that you can store in a repository and share between machines), you should use the file ~/.config/fish/config.fish which is Fish's equivalent to .bashrc in Bash. Since abbreviations are stored in global/universal ...


11

Bash uses readline for interactive input, so syntax highlighting would need to be implemented in that program. I found a Google Groups discussion about how to code such a feature. The fish shell uses its own line editor that is specific to that program, and can not be directly ported. You may find that zsh is very similar to bash, and its line editor is ...


11

~/.config/fish/config.fish is empty by default. To create a custom prompt create a file ~/.config/fish/functions/fish_prompt.fish and fill it with your prompt. Basic example function fish_prompt echo (pwd) '> ' end


11

sudo !! (or sudo bang bang) is one of my most oft used commands. I'm still using just plain old bash that has it just fine. Sorry to hear that fish doesn't implement it correctly. A little googling and I found this: function sudo if test "$argv" = !! eval command sudo $history[1] else command sudo $argv end end There are a lot ...


11

As Elijah says, best practice is to modify the fish_user_paths rather than the global PATH. To avoid ever having to Google this again… Create a couple of functions that only modify fish_user_paths Make both functions autoloading To add to user paths: function addpaths contains -- $argv $fish_user_paths or set -U fish_user_paths $fish_user_paths ...


10

Did you remember to mark $GOPATH in fish as exported? set -x GOPATH /home/<me>/workspace/go-workspace It's not sufficient to test with echo $GOPATH since that will work regardless of whether the variable is exported. Check with bash -c 'echo $GOPATH' which will only print the value of GOPATH if it has been exported. In bash, you export variables ...


9

For sourcing a general sh script in fish, one option is the bass plugin, which can source a bash script's environment variables into fish. If you have fisherman, you can install it with fisher add edc/bass, then run bass source <command>.


8

If you found this question wondering how to change the window/tab title in fish, and the fish_title function works for you (see Chris Page's answer), then here's an example that sets the title to use a shortened version of your working directory. $ funced fish_title function fish_title if [ $_ = 'fish' ] echo (prompt_pwd) else echo $...


8

Some settings, such as the color theme, are stored as universal variables. Run set -U to see them. Note that at the moment universal variables are stored in a file whose name is unique to each host. In the upcoming fish 3.0.0 release we're going to make that file truly global so that simply copying your ~/.config/fish directory tree to another machine will ...


7

fish doesn't implement incremental history search, although it seems to come up fromtime to time. The pre-2.0 documentation has a "Missing features and bugs" section 1 which lists incremental history search fairly far down in the "Possible features" list. The fish-users mailing list includes this message from Axel Liljencratz, dated August 21, 2006, in which ...


6

It looks like you want: set -xg PATH /opt/local/bin /opt/local/sbin $PATH Edit: I see what you mean, this syntax takes some getting used to. It wants spaces instead of colons, and it can't be in quotes, and all the paths in your current PATH must actually exist (in my case, I had /usr/local/sbin in my PATH even though it didn't actually exist, and that was ...


6

You can also set a default editor just for git, which will ignore your default setup: git config --global core.editor pico


6

You can use : https://github.com/junegunn/fzf this library provide powerful search for fish shell.


Only top voted, non community-wiki answers of a minimum length are eligible