fish

How to get user confirmation in fish shell?

邮差的信 提交于 2019-12-20 09:39:51
问题 I'm trying to gather user input in a fish shellscript, particularly of the following oft-seen form: This command will delete some files. Proceed (y/N)? After some searching around, I am still not sure how to do this cleanly. Is these a special way of doing this in fish? 回答1: The best way I know of is to use the builtin read . If you are using this in multiple places you could create this helper function: function read_confirm while true read -l -P 'Do you want to continue? [y/N] ' confirm

How to access remaining arguments in a fish script

帅比萌擦擦* 提交于 2019-12-20 09:29:50
问题 my-fish-script a b c d Say you want to get the all arguments from the second argument onwards, so b c d . In bash you can use shift to dump the first argument and access the remaining ones with "$@" . How would you solve the problem using the fish shell? 回答1: In fish, your arguments are contained in the $argv list. Use list slicing to access a range of elements, e.g. $argv[2..-1] returns all arguments from the second to the last. For example function loop --description "loop <count> <command>

How do I convert this zsh function to fish shell?

时间秒杀一切 提交于 2019-12-14 02:30:43
问题 I have this function which works great in zsh, but I want to convert it to fish shell and I can't get it working. function ogf () { echo "Cloning, your editor will open when clone has completed..." source <(TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts "$1") } 回答1: First of all, since fish's syntax differs from zsh, you also have to change the output of clone_git_file to source it. For example, if clone_git_file is something like: #!/bin/bash echo "FOO=$TARGET_DIRECTORY" echo

How to get the status of previous command in fish script

天涯浪子 提交于 2019-12-12 04:00:08
问题 Say I want to do something in multi commands in a fish script: do_some_important_things if /* previous command succeeds*/ echo Good else echo Failed end I'm not sure how to write the /* previous command succeeds*/ part. I tried $status , but it give me an warning: fish: Variables may not be used as commands. Instead, define a function like 'function status; 0 $argv; end' or use the eval builtin instead, like 'eval $status'. See the help section for the function command by typing 'help

Can fish shell interpolate functions when expanding to their full form?

丶灬走出姿态 提交于 2019-12-11 18:25:23
问题 Given the following abbreviation, where git_branch_name returns the current git branch name: abbr -a ggl 'git pull origin (git_branch_name)' Is there a way to have the the function interpolate when the abbreviation is expanded? # This is what the abbreviation expands to $ git pull origin (git_branch_name) # This is the expansion I am looking for $ git pull origin master 回答1: No, it is not yet possible for an abbreviation to run code when it expands. I expect we'll add this capability before

Defining new fish commands in a script and parse arguments

三世轮回 提交于 2019-12-11 10:59:23
问题 Quick question. Is it possible to define new commands by scripting in fish? I want to program a new command along the lines of this: newFunction --flag1 flag1Input --flag2 flag2Input then space delimited arguments This new function would only by using already-defined commands in a way that functions do, I just want to be able to pass flags to this new function. Is this possible, or do I have to use another language like Python to create an executable for my hypothetical command? 回答1: Sure!

Fish shell and rvm - allowing login shell

两盒软妹~` 提交于 2019-12-11 05:29:00
问题 When I try to use rvm in fish shell, I get this message: ciembor@ciembor ~> rvm use 1.9.2 RVM is not a function, selecting rubies with 'rvm use ...' will not work. You need to change your terminal emulator preferences to allow login shell. Sometimes it is required to use /bin/bash --login as the command. Please visit https://rvm.io/integration/gnome-terminal/ for a example. I get used to use /bin/bash --login , then rvm and then starting fish from bash . But isn't there more straightforward

conda not working correctly with fish shell

天大地大妈咪最大 提交于 2019-12-11 05:06:31
问题 When using conda environments inside the fish shell on macOS, python still points to system python ( /usr/local/bin/python ) instead of pointing to the version of python installed by the conda environment ( <PATH TO MINICONDA>/envs/<ENV NAME>/bin/python ). Everything else (e.g. ipython , jupyter ) points to the correct path, just python isn't behaving as expected. How do I fix this? Details: Performed the following steps in the following order on macOS Mojave 10.14.3: Installed miniconda (a

how to debug fish script?

一笑奈何 提交于 2019-12-10 15:59:56
问题 You can debug a bash script like this: bash -x script [arg1 ...]` Question What is the fish equivalent? 回答1: Fish use a similar flag system: fish -d 3 script.fish Where d is the debug flag followed by the verbosity level: -d or --debug-level=DEBUG_LEVEL specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1. 来源: https://stackoverflow.com/questions/34188411/how-to-debug-fish-script

Can't get RVM to switch rubies

允我心安 提交于 2019-12-10 15:38:58
问题 How do I explicitly point my fish shell to RVM's version of rubies? I'm using fish shell and I installed RVM. However, no matter what I do, RVM doesn't want to switch rubies. rvm rubies =* ruby-2.3.0 [ x86_64 ] > ruby -v ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16] > rvm use ruby-2.3.0 Using /Users/.../.rvm/gems/ruby-2.3.0 > ruby -v ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16] my config.fish file contains: rvm default What am i doing wrong