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

Doesn't actually work at all #29

Closed
Integralist opened this issue Oct 7, 2016 · 5 comments
Closed

Doesn't actually work at all #29

Integralist opened this issue Oct 7, 2016 · 5 comments

Comments

@Integralist
Copy link

$ source .bash-preexec.sh
$ preexec() { echo "just typed $1"; }
$ date

Fri Oct  7 11:42:38 BST 2016

Here is my Bash version (installed via Homebrew):

GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin15.4.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Here is the bash location:

/usr/local/bin/bash
@rcaloras
Copy link
Owner

rcaloras commented Oct 7, 2016

@Integralist thanks for opening. Could you provide a bit more debugging information after you've sourced bash-preexec.sh?

# Contents of your prompt command
echo $PROMPT_COMMAND 
# Contents of preexec 
echo ${preexec_functions[@]}
# Contents of precmd
echo ${precmd_functions[@]}
# Trap should contain bash-preexec's hook
trap
# Check if it's imported
echo "$__bp_imported"

Should return values like..

$ echo $PROMPT_COMMAND 
__bp_precmd_invoke_cmd; __bp_interactive_mode;
$ echo ${preexec_functions[@]}
__bh_preexec preexec
$ echo ${precmd_functions[@]}
__bh_precmd_run_script __bh_bash_precmd __bh_precmd precmd
$ trap 
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU
trap -- '__bp_preexec_invoke_exec' DEBUG    
$ echo $__bp_imported 
defined

Not sure about the homebrew installation, as I didn't create it or use it, but my guess is something is conflicting with your trap or PROMPT_COMMAND.

@Integralist
Copy link
Author

Sure thing @rcaloras the details you've asked for are as follows...

btw, here is my ~/.bashrc file. I found if I move the sourcing of the file to the bottom of that (rather than doing it at the top) I would get some output, but it seemed a bit inconsistent. It might be my crazy prompt code I've got going on that's messing something up

$ echo $PROMPT_COMMAND
history -a

$ echo ${preexec_functions[@]}
preexec

$ echo ${precmd_functions[@]}
precmd

$ trap
trap -- 'shell_session_update' EXIT
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU
trap -- '__bp_preexec_invoke_exec' DEBUG

$ echo "$__bp_imported"
defined

@rcaloras
Copy link
Owner

rcaloras commented Oct 7, 2016

So it looks like bash-preexec is getting pulled in correctly, but PROMPT_COMMAND is not right. If it's right, your PROMPT_COMMAND should have at least the two functions mine does:

$ echo $PROMPT_COMMAND 
__bp_precmd_invoke_cmd; __bp_interactive_mode;

Looking at your ~/.bashrc, it looks like you're overwriting PROMPT_COMMAND in a few places. From your file:

export PROMPT_COMMAND='history -a' # record each line as it gets issued

# override builtin cd so it resets command prompt when changing directories
function cd {
  builtin cd "$@"
  RET=$?

  PROMPT_COMMAND=prompt

  # Disabled following because it seems to be pointless now?
  # That or I just don't know what it was really doing originally?
  #
  # # After each command, append to the history file and reread it...
  # export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"

  return $RET
}

One thing you could do is remove the overwriting of PROMPT_COMMAND and instead define whatever you want in PROMPT_COMMAND as part of a precmd function e.g.

precmd() {
history -a
}

Give it a shot. Let me know if there's anything else I can help with.

@Integralist
Copy link
Author

Heya, so I've got this working now. Totally my bad.

I sorted out my command prompt setup and it works fine 👍

Thanks for taking the time to look into this, you were right PROMPT_COMMAND was getting messed around with when it didn't need to be now I'm using your script

@rcaloras
Copy link
Owner

rcaloras commented Oct 7, 2016

@Integralist no worries! Glad you got it working and I could help! Feel free to checkout some of my other projects as well, bash-preexec was designed to power https://bashhub.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants