Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History is not updated when running multiple commands in the same line #8905

Closed
liuml07 opened this issue Apr 23, 2022 · 7 comments
Closed
Labels

Comments

@liuml07
Copy link

liuml07 commented Apr 23, 2022

Environment

$ fish --version
fish, version 3.4.1
$ echo $version
3.4.1
$ uname -a
Darwin Mingliangs-MacBook-Pro-M1-Max.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 arm64
$ echo $TERM
xterm-256color

Problem

Running following commands, I got "true". I expect "false".

$ sh -c 'env HOME=$(mktemp -d) fish'
$ true
$ false; echo $history[1]
true
@faho
Copy link
Member

faho commented Apr 23, 2022

false; echo $history[1] is one entry in the history.

The history is updated per-commandline.

@faho faho added the question label Apr 23, 2022
@krobelus
Copy link
Member

yeah I think this is the least surprising behavior.

If there is a concrete use case, we have a mechanism for tracing every individual process (set fish_trace 1) that we could perhaps repurpose but it's probably not worth it.

@liuml07
Copy link
Author

liuml07 commented Apr 23, 2022

Thanks for the context.

Is there a way I can get the last command (false) in the same command line?

@faho
Copy link
Member

faho commented Apr 23, 2022

There is no way to change this behavior so that foo; bar counts as two different history elements, or that true and then false count as one history element.

You haven't really explained what you want to do here, so we can't say any more.

@liuml07
Copy link
Author

liuml07 commented Apr 24, 2022

Probably I'm asking a XY question. This probably should be a user question instead of an issue.

I will get email after foo completes using command foo; notify. I now want to know the last command foo from "notify" fish function so the notification is for foo. Running bar; notify will be sending notification including bar.

"notify" includes $status which is for command "foo" but $history[1] is not foo.

I now learnt history is for per-commandline and it makes sense to me. Thanks

@krobelus
Copy link
Member

I just type foo Enter notify Enter.
A wrapper script (like notify foo) would be a cross-shell solution.
Another potential solution is a post-exec hook (function --on-event fish_postexec)

Though I think it's weird that there is no way to access the commandline while the command is running.

$ sleep 3 && echo done, command: (status current-command) commandline: (commandline)
done, command: sleep commandline:

so status current-command works but neither commandline nor history do.

Probably this is best exposed as status current-commandline.

@krobelus krobelus reopened this Apr 24, 2022
@liuml07
Copy link
Author

liuml07 commented Apr 25, 2022

Thanks for providing solutions. They work for me!

I now start using the two solutions both: 1) I added a post-exec hook for command long commands like mvn package and newt ci tail etc, and 2) I will type foo Enter notify Enter for ad hoc commands.

mqudsi added a commit to mqudsi/fish-shell that referenced this issue Oct 22, 2022
Makes it possible to retrieve the currently executing command line as
opposed to the currently executing command (`status current-command`).

Closes fish-shell#8905.
mqudsi added a commit to mqudsi/fish-shell that referenced this issue Oct 23, 2022
Makes it possible to retrieve the currently executing command line as
opposed to the currently executing command (`status current-command`).

Closes fish-shell#8905.
@mqudsi mqudsi closed this as completed in 6ac18de Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants