Skip to content

Commit

Permalink
Merge pull request #5 from woodstok/prompt
Browse files Browse the repository at this point in the history
cmdline filter
  • Loading branch information
woodstok committed Oct 18, 2020
2 parents 1946ab0 + 270806c commit 888be04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ bind-key -n M-l run-shell -b "$HOME/.tmux-butler/modes/quetty-filter -start line
```
bind-key -n M-l run-shell -b "$HOME/.tmux-butler/modes/quetty-filter -start ip"
```
##### modes/quetty-filter -start cmdline #####
The cmdline filter matches default bash prompt regexes to select all bash commands visible in the current window.
The filter tries to match a regex `^\[.*\](#|$)` which is the default bash prompt in many installations.
In addition to the default prompt, you can also specify your shell custom prompt using the environment variable `CUSTOMPROMPT` in `~/.butlerrc`.
eg:
```
CUSTOMPROMPT='λ '
```
This will search for prompts matching the regex at the beginning of a line, in addition to the default prompt regexes.

##### modes/tmuxbuffers #####
Show and select from tmux buffer list
Expand Down
40 changes: 40 additions & 0 deletions filters/cmdline
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# common bash prompt

# Load the CUSTOMPROMPT env variable from rc files if any
SCRIPTDIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/.."
rcfile=$HOME/.butlerrc
if [[ -f "$rcfile" ]]
then
source $rcfile
fi

# load defaults that are not already set
source $SCRIPTDIR/.butlerrc-defaults

# OR all the prompt regexes
defaultBashPrompt1='\[.*\]\$'
defaultBashPrompt2='\[.*\]#'
regexlist=( $defaultBashPrompt1 $defaultBashPrompt2 )
# custom prompt
if [[ -n "$CUSTOMPROMPT" ]]
then
regexlist+=( "$CUSTOMPROMPT" )
fi

promptRegex="^("
first="1"
for regex in "${regexlist[@]}"
do

if [[ "$first" != "1" ]]
then
promptRegex="$promptRegex|"
fi
promptRegex="$promptRegex($regex)"
first=0
done
promptRegex="$promptRegex)"

# grep and remove leading/trailing whitespace
egrep -E -o "$promptRegex.*$" | sed -Ee "s/$promptRegex[[:space:]]*//" -e 's/[[:space:]]*$//'

0 comments on commit 888be04

Please sign in to comment.