I'm trying the fish shell, and it seems to run some functions I've defined in it's config file when I open a new fish tab. For example, if I have this function:
function foo
cd ~/
end
fish will go into an infinite loop as it constantly cd's into my user directory and sources the file. But if I have this:
function foo
ls
end
fish won't show me the output of ls. What is going on?
you may have defined foo as a function and it creates a infinte loop in someway.
try this
function foo
command ls
end
Related
I try to create an alias for ls (should basically just map to ls -lah)
I've tried the following code, but it's not working:
function ls
ls -lah
end
funcsave ls
but when I call it I get this message:
The function 'ls' calls itself immediately, which would result in an infinite loop.
in function 'ls'
called on standard input
What you're looking for is the command command.
I would also recommend to pass any arguments (stored in $argv) to the aliased command.
So your example should be:
function ls
command ls -lah $argv
end
And to do all this with a simple command, you can simply use the alias command.
alias ls "command ls -lah"
Note that usually aliases will not get you the nice auto-complete suggestions that contribute to _fish_'s friendliness. This specific case is an exception because the function and the original command have the same way, but otherwise, here are two ways to get completions anyway:
You can use the complete command to tell fish that your alias uses the same completions as the aliased command.
The balias plugin
serves as an alternative to alias and does just that.
fish also offers an abbr command. It works slightly different and will actually expand the abbreviated command to the full command in the command line, and then fish will have no problem giving you all the auto-completion suggestions that it knows.
You need the command keyword. Also, pass the function's arguments to ls
function ls
command ls -lah $argv
end
If you need to make alias of ls, then the above answers are OK.
However, fish already has a command for ls -lah, which is la.
On Ubuntu Server 16.10 x64 with fish 2.3.1, my uru_rt exe generates this function on stdout
function uru
set -x URU_INVOKER fish
# uru_rt must already be on PATH
uru_rt $argv
if test -d "$URU_HOME" -a -f "$URU_HOME/uru_lackee.fish"
source "$URU_HOME/uru_lackee.fish"
else if test -f "$HOME/.uru/uru_lackee.fish"
source "$HOME/.uru/uru_lackee.fish"
end
end
when run via uru_rt admin install. The uru function provides the golang-based cross-platform ruby version manager tool https://bitbucket.org/jonforums/uru
On bash systems, I inject the uru function by placing eval "$(uru_rt admin install)" in a startup file so that uru is present in the shell.
On fish, running eval (uru_rt admin install) rewards me with this failure
$ eval (uru_rt admin install)
Missing end to balance this begin
- (line 1): begin; function uru set -x URU_INVOKER fish # uru_rt must already be on PATH uru_rt $argv if test -d "$URU_HOME" -a -f "$URU_HOME/uru_lackee.fish" source "$URU_HOME/uru_lackee.fish" else if test -f "$HOME/.uru/uru_lackee.fish" source "$HOME/.uru/uru_lackee.fish" end end
^
from sourcing file -
called on line 60 of file /usr/share/fish/functions/eval.fish
in function “eval”
called on standard input
source: Error while reading file “-”
I've also tried set u1 (uru_rt admin install); eval "$u1" with the same result.
As expected, when I do uru_rt admin install > ~/.config/fish/functions/uru.fish the uru function becomes persistently available. While this is an option, my preference is to use eval in ~/.config/fish/config.fish
As a noob to fish, how do I dynamically inject this uru function into the environment using eval similar to bash's eval "$(uru_rt admin install)"?
Fish's eval is a wrapper function around its source builtin, and it seems there's some weirdness (maybe even a bug) going on with it's argument splitting when you pass multiple lines..
However, in this case it's simpler, faster and actually working if you just use source, like uru_rt admin install | source.
That assumes though that uru_rt admin install really needs to be called - if all it does is print that code to stdout, without changing it, you can also simply save the function, e.g. in ~/.config/fish/functions/uru.fish.
This seems so basic to me, but I've been unable to figure it out. So I wrote a completion that auto completes my code directories like the following:
complete --command dev --exclusive --arguments '(__fish_complete_directories (~/Code/))'
Now I'm trying to write a function that cd's into the chosen directory from the dev completion above.
This doesn't work but I hope you get what I'm trying to do:
function c
cd dev
end
So when typing c, I want to get all my directories in the ~/Code/ directory as tab completion options, then when I select one, I want my current path to be taken to the chosen directory.
Btw - fish needs more docs :)
So you're trying to do two things:
Create a function c that cd's to its argument
Make tab-completing c show paths in ~/Code
This is straightforward:
function c
cd $argv
end
complete --command c --exclusive --arguments '(__fish_complete_directories ~/Code/)'
I'm not sure what dev is meant to be, but to be clear, the --command option to complete adds completions to an existing command. It does not define a new command.
Regarding documentation, there's lots at http://fishshell.com/docs/current/index.html. If there's areas you think need more coverage please open an issue at https://github.com/fish-shell/fish-shell/issues.
I have tried running a script in the MATLAB command line and it says
>> run(ex1)
Undefined function or variable 'ex1'.
>> run(exp1.m)
Undefined variable "exp1" or function "exp1.m".
You're using run wrong. You need to encapsulate the script name as a string:
>> run('ex1.m');
You'll need to make sure that your working directory is set to where the script is located, because the above way to call run assumes local referencing.
Please read the documentation on run in the future: http://www.mathworks.com/help/matlab/ref/run.html
However, you can just type in ex1 in the command prompt and it'll still work... as long as you're in the working directory of where the script is run, and ensuring that you don't have any variables in your workspace that have the same name as the script file:
>> ex1
I want to accomplish a loop over R code within an IPython notebook. What is the best way to do this?
l = []
for i in range(10):
# execute R script
%%R -i i -o result #some arbitrary R code
# and use the output
l.append(result)
Can this be done inside a notebook (Looping over next cell)?
Have you looked into rmagic and rpy2 module?
If you have R scripts, then you can call them and assign their output to a variable using the shell command notation:
var=!R_script arguments....
The above does not need you need you to install rpy2 since ! shell command execution is basic in ipython. You can pass values of variables from ipython notebook by using $var in the arg list.