Make zsh completion more bash-like / best practice with zsh completion - autocomplete

Using bash I did like to do something like this:
$ l
file15165
file23132
file31351
xyzfile
$ $CMD f<TAB>
(f gets completed to "file", I type "*", [23] or whatever)
$ $CMD file*<Enter>
This way I am sure the command is executed on all the files I want it to.
When I try to do this with zsh, this happens:
$ l
file15165
file23132
file31351
xyzfile
$ $CMD f<TAB>
(f is completed to "file15165", I have to press <backspace> five times and then type "*")
$ $CMD file*<Enter>
Which is quite ineffective. Now how can I achieve the bash behaviour using zsh? Or how would a zsh user attempt to do what I am doing?

It appears I had setopt menucomplete in my .zshrc, which resulted in the explained behaviour. Removing it fixed it.

Related

How to create a alias in fish shell

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.

Terminal prompt disappears when a named pipe is used

I'm trying to use named pipes in a project. I have two terminals open, Terminal A and Terminal B.
In terminal A, I issued this command:
mkfifo myFifo && tail -f myFifo | csh -s
It seems as if standard out is being redirected somewhere else, though, because my prompt disappears and some commands aren't reflected in terminal A.
For example, if in terminal B I begin a python session via issuing echo "python" > myFifo, then echo "print 'Hello, World'" > myFifo, I don't see Hello, World in terminal A.
However, if I issue echo ls > myFifo within terminal B, I see the correct output from ls in terminal A.
Does anyone know why sometimes the output appears and sometime it doesn't?
I'm running on CentOS 6.6
Thanks,
erip
You read from the FIFO with csh, if you start an interactive Python shell in csh, then it won't be reading from the FIFO because it's busy running python.
Python doesn't somehow automagically do a REPL on the FIFO. How should it even know about the FIFO? It has no knowledge of it.
You could, perhaps, tell Python to read commands from the FIFO with something like:
>>> import os, sys, time
>>> fifo = open(os.open('myFifo', os.O_NONBLOCK), 'r')
And then:
$ echo 'print(42+5)' > ! myFifo
Will give you:
>>> eval(fifo.read())
47
Perhaps there's also a way to tell Python to read commands from myFifo by overwriting sys.stdin, but I can't get that working in my testing.
It's a bit unclear to me what exactly you're trying to achieve here, though. I suspect there might be another solution which is much more appropriate to the problem you're having.

In IPython every shell command is run by prefixing it with "!" but few commands run without that, What is the reason behind it?

In case of "ls" command it runs with and without the prefix "!". In case of "cat fileName" it's the same, but when you consider "wc -l fileName" it works only with "!" prefix.
When you combine cat and wc command "cat fileName | wc -l" executed successfully without "!" prefix.
I don't understand the logic behind this prefix "!" in ipython.
Thank you in advance
(I am new to python programming, if it sounds silly question please forgive me.)
IPython tries to make interactive programming as comfortable as possible. Some shell builtins like ls, cd or cat are basic commands to navigate in unix shells. IPython, as a "Python Shell" provides the same functionally for convenience. Along with features like colored output, etc.
The !command is for executing arbitrary shell code and is much more powerful. It can be used to run any command you can type in a normal shell and can also catch its output.
Compare ls with !ls. The former will print the content in your current directory with nice coloring. The latter will print the same list, but just plain text.
But note that you can do really cool things with !command:
files = !ls
for f in files:
print("I like this file:", f)
Which reads the output of ls into a python array files which you can use in your code just like any other array.
To sum up: if you just want to navigate, you usually use the standard commands, if available. If you need to capture the output or run programs you have to use the !command syntax.

Is there a way to issue boilerplate debugger commands on the command line?

I'd love to be able to do something like:
perl -d my-program.pl -c 'b postpone Foo::Bar::some_func'
i.e. specify as part of the invocation of perl -d a command that I would ordinarily enter at the debugger prompt, namely b postpone Foo::Bar::some_func.
From man perldebug, you could use source file
Put some common commands in a file and source that manually after starting the debugger.

Running command using XARG

I have example file: test_file
//--- Test File--
**RUN_THIS
RUN_THIS00
RUN_THIS01
DONT_RUN00
DONT_RUN00
RUN_THIS02**
where RUN_THIS* & DONT_RUN* are commands.
I would like to run only RUN_THIS commands from test_file without editing the file.
I am looking for option like
cat test_file | grep RUN_THIS | xargs {Some option to be provided to run run_this}
I cannot start new shell
Something like this perhaps?
for cmd in $(grep RUN_THIS < test_file); do
$cmd --some-option-to-be-provided-to-run-this
done
That should work okay as long as there are no spaces in the commands in test_file.
eval `grep RUN_THIS test_file`
Note also the avoidance of a Useless Use of Cat.
Actually, you may have to add a semicolon to the end of each command in test_file, or change the grep to something which adds the necessary semicolons.
eval `awk '/RUN_THIS/ { print; print ";" }'`
I'm not sure I understand the requirement to not start a new shell. Under the hood, the backticks run a subshell, so this might violate that requirement (but then ultimately every external command starts a new process, which starts out as a fork of the current shell process when you run a shell script). If you are scared of security implications, you should not be using a shell script in the first place, anyhow.
To run new shells you need to incorparate "ksh" in your command.
In its simplest form
RUN_THIS00='ls'
echo $RUN_THIS00 | ksh