Comments (5)
I've considered this before. @jombooth What about the case where we have duplicate commands and ignoredups
set? e.g. You enter the same command twice. History will not change (no increment in number) but we should invoke preexec
.
from bash-preexec.
@davefx thanks for reporting! Giving it a look.
from bash-preexec.
I have an idea for fixing this; the output of fc -l (a replacement for history, see #53) gives a number for each command, like this:
1048 set +x
1049 ls
1050 ld
1051 fc -l 0
if we store the last processed command number, then we can skip preexec in the case it hasn't changed.
from bash-preexec.
Would it make sense to replace the existing short-circuit checks in __bp_preexec_invoke_exec
with this check? Put another way is it the case that preexec should fire if-and-only-if the command number has changed?
from bash-preexec.
What about comparing this_command
to BASH_COMMAND
in __bp_preexec_invoke_exec
?
$ tmux
tmux $ foo() {
> if [[ -z $i ]]; then
> i=0
> else
> ((i++))
> fi
> (set -o posix; set) > ~/env.$i
> }
tmux $ preexec_functions+=(foo)
tmux $ echo 1 2 3
tmux $ <CTRL + D>
$ grep 'this_command' ~/env.0 ~/env.1
~/env.0:this_command='echo 1 2 3'
~/env.1:this_command='echo 1 2 3'
$ diff ~/env.0 ~/env.1
4,5c4,5
< BASH_ARGC=()
< BASH_ARGV=()
---
> BASH_ARGC=([0]="1")
> BASH_ARGV=([0]="/home/jeffrey/.bash_logout")
7c7
< BASH_COMMAND='echo 1 2 3'
---
> BASH_COMMAND='[ "$SHLVL" = 1 ]'
9,10c9,10
< BASH_LINENO=([0]="67" [1]="10")
< BASH_SOURCE=([0]="main" [1]="/home/jeffrey/src/bash-preexec/bash-preexec.sh")
---
> BASH_LINENO=([0]="213" [1]="5" [2]="11")
> BASH_SOURCE=([0]="main" [1]="/home/jeffrey/src/bash-preexec/bash-preexec.sh" [2]="/home/jeffrey/.bash_logout")
26c26
< FUNCNAME=([0]="foo" [1]="__bp_preexec_invoke_exec")
---
> FUNCNAME=([0]="foo" [1]="__bp_preexec_invoke_exec" [2]="source")
103c103
< __bp_last_argument_prev_command=
---
> __bp_last_argument_prev_command=3
723c723
< i=0
---
> i=1
from bash-preexec.
Related Issues (20)
- Preexec is called when exiting bash with Ctrl-D HOT 2
- Return immediately when running in Zsh HOT 3
- [Bug] HISTCONTROL ignore* setting should be respected HOT 7
- `__bp_preexec_invoke_exec "$_"` printed when running multiple commads
- Tests fail with bats 1.5.0 HOT 7
- official way to detect whether bash-preexec is loaded HOT 2
- Line number exit outpu command ? HOT 1
- Bash 5.1 supports making PROMPT_COMMAND an array HOT 5
- ShellCheck highlights several issues with the file - Shellcheck could be disabled, or issues resolved HOT 2
- post_cmd functionality addition HOT 2
- Functions called in opposite order in midnight commander subshell HOT 2
- Some tests fail with bats 1.9 HOT 6
- preexec() does not work where as precmd() is working as intended. HOT 1
- Library Authors documentation can still lead to issues HOT 2
- preexec $1 is missing some commands HOT 1
- detailed bash log with preexec and precmd HOT 2
- Not working on Windows using Bash in MSYS2 HOT 7
- preexec doesn't work for no-op command `:`
- `bash-preexec` will cause `hishtory` to be particularly time-consuming for commands including pipeline.
- New release when?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bash-preexec.