fish

How to test if result of a command contains a string in fish shell?

我是研究僧i 提交于 2019-12-10 15:17:31
问题 I'm trying to write a brief function to allow me to toggle wemo lights on and off from the command line. Basically I have a command that if i type wemo status will return either Switch: Lights 1 if the lights are on or 0 if they are off. I'd like to write a fish function that essentially lets me toggle them: function lights --description 'Toggle lights' if contains (wemo status) "Lights 1" wemo switch "Lights" off else wemo switch "Lights" on end end Though this doesn't work. I'm thinking

How to prevent iterm2 from closing when typing Ctrl-D (EOF)

走远了吗. 提交于 2019-12-10 14:06:35
问题 I am using fish shell. When I type Ctrl-D, it sends a EOF to my terminal and then terminal closes. I want to make it such that ctrl-D does not close my iterm2. I saw that people have set up IGNOREEOF in bash shell like this: https://unix.stackexchange.com/questions/27588/how-can-i-keep-controld-from-disconnecting-my-session However, I don't think this variable exists in fish. Does anybody know how I can force iterm2(with default fish shell) to not close on ctrl-D? 回答1: This is the default key

List all aliases available in fish/bash shell

寵の児 提交于 2019-12-10 12:38:35
问题 Is there a way to list all aliases, something like: $ ls-aliases .. "cd .." la "ls -Gla" gs "git stash" etc... Also is it possible to add human readable descriptions to aliases ? I'm on a MacOSX 回答1: In bash : To list all aliases: alias To add a comment, just put it at the end of the command, e.g.: $ alias foo='echo bar #some description' $ foo bar $ alias foo alias foo='echo bar #some description' 回答2: Note that in fish the alias command creates a function using the alias name that wraps the

test command: difference between -n and -z

邮差的信 提交于 2019-12-10 09:53:10
问题 Given this driver function that only produces output given certain input: function driver -a arg test $arg = 1; and echo OK return 0 end Things work OK when the function emits output: $ driver 1 | od -c 0000000 O K \n 0000003 $ test -z (driver 1); and echo no output; or echo some output some output $ test -n (driver 1); and echo some output; or echo no output some output But in the no output case: $ driver 0 | od -c 0000000 $ test -z (driver 0); and echo no output; or echo some output no

Fish command substitution doesn't work like in bash or zsh

回眸只為那壹抹淺笑 提交于 2019-12-10 04:42:03
问题 I have stumbled on a problem with the fish shell (which is my favorite shell) when I am trying to use command substitution: gcc (pkg-config --libs --cflags gtk+-2.0 cairo) -o drawing_widget drawing_widget.c gcc: erreur: unrecognized command line option ‘-pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib

How to make fish shell use an rvm ruby by default

风流意气都作罢 提交于 2019-12-09 16:13:45
问题 I'm using fish shell 2.10 on Mac OS X 10.9.1. I would like to use a Ruby that I have installed using RVM as the default in my terminals, however I can't seem to make this work. I've tried rvm use 2.1.0 --default but upon opening a new terminal I still get the following: > which ruby /usr/bin/ruby Running the rvm command causes the ruby to be loaded: > which ruby /usr/bin/ruby > rvm [...] > which ruby /Users/alex/.rvm/rubies/ruby-2.1.0/bin/ruby But it's annoying to have to do this every time I

Creating autocomplete script with sub commands

亡梦爱人 提交于 2019-12-09 05:45:04
问题 I'm trying to create an autocomplete script for use with fish; i'm porting over a bash completion script for the same program. The program has three top level commands, say foo , bar , and baz and each has some subcommands, just say a b and c for each. What I'm seeing is that the top level commands auto complete ok, so if I type f I'm getting foo to autocomplete, but then if I hit tab again to see what it's sub commands are, i see foo , bar , baz , a , b , c and it should just be a , b , c I

How to get the program name in a fish shell script?

﹥>﹥吖頭↗ 提交于 2019-12-08 15:59:02
问题 In bash, as in ruby, the program name is given by $0. What is it in fish? I can do the following if I have to: set PROGRAM (ps --no-header -o args -p %self | egrep -o '\S+')[2] But I'm sure the program name must be already available somewhere. I could also set the program name in variable at the stub of each program, but that has maintenance problems. 回答1: To get the same result as your command, it is the script filename you are looking for. This information is not stored in a variable, but

Make Fish start me in a directory other than HOME

為{幸葍}努か 提交于 2019-12-07 22:30:15
问题 I'm running Fish on a Vagrant-controlled VM. I want to use ~vagrant as the place where VM-specific configuration gets dumped, so that's my $HOME . I have /vagrant as a directory shared with the host, and that's where I want to be all the time. When I log in to the VM, I'd like Fish to dump me into /vagrant/ . In Bash, I'd do this by putting cd /vagrant/ into ~/.bashrc . However, I see there's another question about changing directories in Fish and the comments suggest that putting cd /vagrant

Is there a way to detect OS in fish shell akin to the OSTYPE variable in bash?

五迷三道 提交于 2019-12-06 19:27:03
问题 Right now I'm forced to resort to using uname to get the operating system name and it works. But in bash there is the OSTYPE environment variable that is automatically set and I was wondering if there is something similar. 回答1: From the fish user documentation it seems that the canonical way to execute code conditionally depending on the operating system type is using a switch statement with the uname results. See example: switch (uname) case Linux echo Hi Tux! case Darwin echo Hi Hexley!