Comments (7)
FYI can you just use the time
command? e.g. time echo "hello"
My guess is you need to do this for every command though :)
Weird, I use on both mac and linux and it's fine.
Here's what my system looks like for linux. Same as yours.
elementz@Kashmir:~/git/bashhub (master)$ uname -a
Linux Kashmir 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
elementz@Kashmir:~/git/bashhub (master)$ echo $BASH_VERSION
4.3.11(1)-release
elementz@Kashmir:~/git/bashhub (master)$ bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
I can also use your setup fine and it works on my linux box:
elementz@Kashmir:~/git/bashhub (master)$ preexec () {
date_before=$(date +%s.%N)
}
elementz@Kashmir:~/git/bashhub (master)$
elementz@Kashmir:~/git/bashhub (master)$ precmd () {
if [ -z "$date_before" ]; then
return 0
fi
local date_after
date_after=$(date +%s.%N)
printf "\n%.2fs\n\n" $(bc<<<$date_after-$date_before)
}
elementz@Kashmir:~/git/bashhub (master)$ sleep 1
1.01s
You might be using something else in your PROMPT_COMMAND. What does it return?
elementz@Kashmir:~/git/bashhub (master)$ echo "$PROMPT_COMMAND"
__bp_precmd_invoke_cmd; __bp_interactive_mode;
Something also may be interfering with Bash's DEBUG trap. Do you have any other bash plugins you are using?
from bash-preexec.
Run also set -o verbose
or set -o xtrace
to see what is going on
from bash-preexec.
The environments (mac and ubuntu) were almost identical, but there was only 1 difference: on ubuntu I am also using z. After I've installed z on mac, it has also started to misbehave.
Given that z is a popular plugin, is there any possibility to run both z and preexec ?
❯ echo "$PROMPT_COMMAND"
__bp_precmd_invoke_cmd; history -a; echo -ne "\\033]0;${PWD##*\/}\\007"; __bp_interactive_mode;
_z --add "$(command pwd -P 2>/dev/null)" 2>/dev/null;
3.61s
❯ set -o verbose
__bp_precmd_invoke_cmd; history -a; echo -ne "\\033]0;${PWD##*\/}\\007"; __bp_interactive_mode;
__bp_preexec_invoke_exec
type -t $precmd_function
date +%s.%N
bc<<<$date_after-$date_before
37.54s
__bp_preexec_invoke_exec
__bp_preexec_invoke_exec
__bp_preexec_invoke_exec
_z --add "$(command pwd -P 2>/dev/null)" 2>/dev/null;
__bp_preexec_invoke_exec
__bp_trim_whitespace "$1"
__bp_trim_whitespace "$command"
__bp_trim_whitespace "$command"
__bp_trim_whitespace "$command"
__bp_trim_whitespace "$command"
__bp_trim_whitespace "$command"
history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"
type -t $preexec_function
date +%s.%N
command pwd -P 2>/dev/null
[[ -n $(git branch 2> /dev/null) ]] && echo " "
git branch 2> /dev/null
parse_git_branch
git rev-parse --abbrev-ref HEAD 2> /dev/null
from bash-preexec.
Just installed z
and played with it a bit. Cool plugin. I believe there's a simple fix :)
Just make sure bash-preexec.sh is imported/sourced after you import z.sh. The __bp_interactive_mode
function needs to be the last thing in your prompt command. Preexec needs that function to be able to tell when you're entering commands on the comamnd line vs something like your git prompt or z which is invoked as part of PROMPT_COMMAND.
So your PROMPT_COMMAND should have __bp_interactive_mode last like this:
19:32:38-rcaloras-~$ echo $PROMPT_COMMAND
__bp_precmd_invoke_cmd; _z --add "$(command pwd -P 2>/dev/null)" 2>/dev/null; __bp_interactive_mode;
give that a shot.
from bash-preexec.
You must source z
before bash-preexec
from bash-preexec.
Added f4c5adb for clarity
from bash-preexec.
Thanks, it solved my issue.
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.