Ok, I think I have a clue what is going on.
The behaviour you are observing in zsh and bash when executing echo $(mc)
is caused by mc
.
When you run mc
normally, it doesn't react when Ctrl+c is pressed, since it ignores SIGINT
. The way to end mc
is by pressing F10 and Enter.
When you run echo $(mc)
the input goes to the mc
process, so it is no wonder that when you press Ctrl+c nothing will happen, because mc
ignores SIGINT
.
But when you run echo $(mc)
and press F10 and Enter it will react.
(When I then press F10 and Enter again it actually quits; it should quit at the first try but I have no idea why it does not.)
From this fact I deduce that Midnight Commander is running normally, but the output from it is put into the shell buffer, so it can later be used by echo
.
Something we should consider normal.
Also you think that bash and zsh are hanging, but I would say that they are not hanging but waiting for the echo
command to return.
But echo
can only return when mc
returns, which it only does when F10 and Enter are pressed.
With this we can also explain what happens when you press Ctrl+z.
By pressing the combination mc
goes to sleep like it would if you had run mc
normally and echo
is still waiting for the sleeping mc
.
So everything is normal behavior.
Except for what fish does.
fish seems to start commands run with echo ($command)
in the background.
It kind of makes sense, since such a command normally does not need any input.
For the why and how I have no answer.
But you can see that it runs in the background when you enter
echo (mc)
jobs
With two functions in your .bashrc
file, you can use the directory stack for some navigation
function down ()
{
if [[ -z "$1" ]]
then
n=1
else
n=$1
fi
for ((i=0; i<$n; i++ ));
do
pushd .. > /dev/null
done;
}
function up ()
{
if [[ -z "$1" ]]
then
n=1
else
n=$1
fi
for ((i=0; i<$n; i++ ));
do
popd > /dev/null
done;
# dirs -c # To clear directory on up motion
}
Where you can use down N
and up N
, respectively.
Sample usage:
~/tmp/bash/dir1/dir2/dir3$ down 4
~/tmp$ up 2
~/tmp/bash/dir1$ up 2
~/tmp/bash/dir1/dir2/dir3$ down 2
~/tmp/bash/dir1$ down 1
~/tmp/bash$ up 3
~/tmp/bash/dir1/dir2/dir3$
Of course, you cannot use up N
before using down N
. Unexpected things might happen, or error messages may appear.
Best Answer
A fish alias is actually implemented as a function. To save a function, you need
funcsave
. So this is the sequenceThat creates ~/.config/fish/functions/foo.fish which will then be available in any fish session.