-
Notifications
You must be signed in to change notification settings - Fork 21
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
26 Complete full lines #39
Changes from all commits
2c44325
54cac8b
f0e1993
c2e9119
05b5e3f
24e9469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
#!/bin/sh | ||
|
||
# Usage: Get a list of all currently visible words: | ||
# sh tmuxwords.sh '' -a | ||
# sh tmuxcomplete words '' -a | ||
# | ||
# Get all visible words beginning with `foo`: | ||
# sh tmuxwords.sh ^foo -a | ||
# sh tmuxcomplete words ^foo -a | ||
# | ||
# Get all visible lines beginning with `foo`: | ||
# sh tmuxcomplete lines ^foo -a '' | ||
|
||
if [ -z "$TMUX_PANE" ]; then | ||
echo "Not running inside tmux!" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
MODE="$1" PATTERN="$2" LISTARGS="$3" CAPTUREARGS="$4" | ||
|
||
capturepane() { | ||
if [ tmux capture-pane -p &> /dev/null ]; then | ||
# tmux capture-pane understands -p -> use it | ||
|
@@ -22,21 +27,31 @@ capturepane() { | |
fi | ||
} | ||
|
||
splitwords() { | ||
# copy lines and split words | ||
sed -e 'p;s/[^a-zA-Z0-9_]/ /g' | | ||
# split on spaces | ||
tr -s '[:space:]' '\n' | | ||
# remove surrounding non-word characters | ||
grep -o "\\w.*\\w" | ||
} | ||
|
||
splitlines() { | ||
# remove surrounding whitespace | ||
grep -o "\\S.*\\S" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's odd that this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. The behavior differs when there are trailing non-space non-word characters. Given this line
would capture
Because we always start completion at a word character it might make more sense to use
which would capture
That might not be wanted for the lines presented in Unite, though. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually my original concern is not valid. But the problem you bring up is definitely tricky. I'd say that for full lines, the user really does want the entire line, including non-word chars. This would be a problem for any completion engine that does not do partial matches (I'm guessing the built-in omni complete), but it shouldn't be a problem for Neocomplete and definitely not for Unite. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually leaning towards different modes (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. In the meantime whatever gets it merged is fine with me :) |
||
|
||
# list all panes | ||
tmux list-panes $2 -F '#{pane_active}#{window_active}-#{session_id} #{pane_id}' | | ||
tmux list-panes $LISTARGS -F '#{pane_active}#{window_active}-#{session_id} #{pane_id}' | | ||
# filter out current pane (use -F to match $ in session id) | ||
grep -v -F "$(tmux display-message -p '11-#{session_id} ')" | | ||
# take the pane id | ||
cut -d' ' -f2 | | ||
# capture panes | ||
capturepane "$3" | | ||
# copy lines and split words | ||
sed -e 'p;s/[^a-zA-Z0-9_]/ /g' | | ||
# split on spaces | ||
tr -s '[:space:]' '\n' | | ||
# remove surrounding non-word characters | ||
grep -o "\\w.*\\w" | | ||
capturepane "$CAPTUREARGS" | | ||
# split words or lines depending on mode | ||
( [ "$MODE" = "lines" ] && splitlines || splitwords ) | | ||
# filter out words not beginning with pattern | ||
grep "$1" | | ||
grep "$PATTERN" | | ||
# sort and remove duplicates | ||
sort -u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.