Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting a command over multiple lines in fish-shell

Tags:

fish

I'm trying to split my list of additional paths on to multiple lines in my fish config:

# Path additions
for i in \
        ~/Library/Haskell/ghc-7.0.2/lib/gtk2hs-buildtools-0.12.0/bin \
        ~/Library/Haskell/bin \
        /Applications/MacVim.app/Contents/MacOS \
        /opt/local/bin \
        /usr/local/bin \
        /usr/local/git/bin \
        /Users/lyndon/.gem/ruby/1.8/bin
    if not contains $i $PATH
        set -x PATH $i $PATH
    end
end

However, this doesn't seem to work unless all the items are on one line.

Is this possible? I can't seem to find any information on doing this.

Alternatively, is there a way to use a list/array literals to do this?

like image 967
Lyndon Maydwell Avatar asked Apr 14 '11 14:04

Lyndon Maydwell


People also ask

How do you split a long command sequence into multiple lines?

To split long commands into readable commands that span multiple lines, we need to use the backslash character (\). The backslash character instructs bash to read the commands that follow line by line until it encounters an EOL.

How do you write a multiline command in shell?

Using a Backslash. The backslash (\) is an escape character that instructs the shell not to interpret the next character. If the next character is a newline, the shell will read the statement as not having reached its end. This allows a statement to span multiple lines.

What is multi line command?

Command input may span multiple lines for the commands whose names are listed in the multiline_commands argument to cmd2. Cmd. __init__() . These commands will be executed only after the user has entered a terminator.

How do you customize fish shells?

Simply run fish_config to open the web client. From there, you can choose the themes, colors, prompts, inspect the FSH functions and variables, and see the history of commands used. Changes are, in turn, stored in the ~/. config/fish folder and can be accessed and edited there to dodge the optional web configuration.


1 Answers

I'm using fish 2.0.0 on OSX 10.8.5 and your example works as I would expect (for paths that exist on my machine).

Running this code

# Path additions
for i in \
    ~/bin \
    ~/.config/fish/functions
    if not contains $i $PATH
       echo $i 
    end
end

where ~/bin is set on PATH and ~/.config/fish/functions is not, outputs: ~/bin

I appended the above to my fish config and then ran it like this: . ~/.config/fish/config.fish

Here is a little more info on multiline editing: http://fishshell.com/docs/2.0/index.html#multiline

There are no array literals in fish. You can read more about fish arrays in the docs. http://fishshell.com/docs/2.0/index.html#variables-arrays

like image 188
Luke Avatar answered Oct 16 '22 08:10

Luke