-
Notifications
You must be signed in to change notification settings - Fork 89
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
Display command execution time #4
Comments
FYI can you just use the 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? |
Run also |
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. ❯ 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 |
Just installed Just make sure bash-preexec.sh is imported/sourced after you import z.sh. The 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. |
You must source |
Added f4c5adb for clarity |
Thanks, it solved my issue. |
I want to display the time spent running a command. I've defined the following functions:
On bash
version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)
on a mac works as expected. However, on a ubuntu 14.04version 4.3.11(1)-release (x86_64-pc-linux-gnu)
it doesn't.It looks like the order of execution on mac is
prexec -> precmd
, while on linux isprecmd - > preexec
, but even if I swap the function names on linux it still doesn't work as expected.Also, I've used gdate instead of date on mac. (from coreutils)
Any ideas how to make it work on linux?
The text was updated successfully, but these errors were encountered: