Git Product home page Git Product logo

Comments (7)

rcaloras avatar rcaloras commented on July 24, 2024

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.

d630 avatar d630 commented on July 24, 2024

Run also set -o verbose or set -o xtrace to see what is going on

from bash-preexec.

alexbardas avatar alexbardas commented on July 24, 2024

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.

rcaloras avatar rcaloras commented on July 24, 2024

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.

d630 avatar d630 commented on July 24, 2024

You must source z before bash-preexec

from bash-preexec.

rcaloras avatar rcaloras commented on July 24, 2024

Added f4c5adb for clarity

from bash-preexec.

alexbardas avatar alexbardas commented on July 24, 2024

Thanks, it solved my issue.

from bash-preexec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.