Dup Ver Goto 📝

FishQuestions_01

PT2/shell/fish does not exist
To
97 lines, 565 words, 3113 chars Page 'FishQuestions_01' does not exist.

1 From Bash to Fish

Bash to fish questions:

1.1 How to prevent command substitution having side effects.

For example:

cd; echo (cd /) (ls)

will echo a list of files from / whereas in bash it would be from home. (More generally, one cannot guarantee that command substitutions are side-effect free. Side-effect free is good.

1.2 ! history and histverify

On bash, with histverify set, if I type sudo !!, it brings the last command to the edit buffer, appends it to sudo, but doesn't execute it.

1.3 histverify

Consider, with histverify

cd; !l; !.; !a

This will recall the previous commands starting with l, ., a, insert them, and then allow me to edit the resulting command before executing.

1.4 Math inside ((..)). In bash

A=1
((A += 2))

Is

set A 1
set A (math $A + 2)

the only way to do this?

1.5 Edit with vim

How do I open the edit buffer in vim, like C-x C-e does in bash?

General Questions

1 Programmatically modifying the edit buffer

e.g. to emulate history and histverify functionality, or something else, we want to recall stuff from the history and arrange it into the edit buffer rather than executing it.

A use case in bash is using multiple !'s with histverify, then C-x C-e to edit the command in vim before executing. (In bash I'd actually like a vimverify function so that what is returned from vim isn't immediately executed. Perhaps to avoid temporary files, we could use file descriptor 3 with vim to send things in and out without tying up stdin and stdout. Mind you, if there is a tmpfs guaranteed to be a ramdisk, then temp files work fine.)

fish -c

If I want to pass a string containing fish commands to fish -c, the text in the quotes isn't syntax highlighted (as would happen inside (...) in bash when edited in vim). Also I can't use single quotes in that string without escaping.

functions

in bash, if I define a function, then use (..) to run something in a subshell, that function is visible in the subshell. This isn't the case with fish -c. A begin sub;..end should make everything in the parent environment visible in the child environment.

An alternative is a kind of 'push state..pop state' stack thing where the complete state of fish is pushed onto a stack. Then this opens other possibilities with state management beyond subshells.

Again, a begin subshell or just begin sub would be handy here. (As commented above, subshells prevent side-effects in the current shell, which is sometimes desirable, and fish -c with a quoted string is awkward.)

Is function defied, tmp func name

It would be nice to be able to define a function with a new temporary name.

More Subshell Stuff

Parallel subshells

In bash we can do

for s in $(seq 5); do
    (
        echo "$s"
        sleep 1
        echo "x$s"
    )&
done

The bits in the (..) will run in parallel, as well as not generating side-effects in the main shell. We can change from doing the bit in the (...) serially or in parallel by simply changing a ; to a &. Is there a correct, easy way to do this in fish?