=== removed file 'tmux-buffer-paths' --- tmux-buffer-paths 2012-07-29 20:30:05 +0000 +++ tmux-buffer-paths 1970-01-01 00:00:00 +0000 @@ -1,5 +0,0 @@ -#!/bin/zsh -export MATCH_RE MATCH_TYPE -MATCH_TYPE=-P -MATCH_RE="(^|(?<=['\" ]))/[-_/.[:alnum:]]+" -exec tmux-buffer-slmenu "$@" === renamed file 'tmux-buffer-slmenu' => 'tmux-buffer-urls' --- tmux-buffer-slmenu 2012-07-29 20:30:05 +0000 +++ tmux-buffer-urls 2012-07-29 19:11:21 +0000 @@ -12,24 +12,18 @@ -a --append append url to the command -p --prompt TEXT use TEXT as a prompt -environment: - MATCH_RE must be set to grep extended regular expression to match - description: - Checks current tmux buffer for regexp matches and shows them using slmenu. - When user selects one match it is then passed to a command that was given - as an argument via stdin. In case -a option was used, it is passed as last + Checks current tmux buffer for URLs and shows them using slmenu. When + user selects one URL it is then passed to a command that was given as + an argument via stdin. In case -a option was used, it is passed as last argument instead. If no command was given, the result is saved as new tmux buffer. END exit 0 fi -if [[ -z $MATCH_RE ]]; then - echo 'please set MATCH_RE environment variable (use --help for details)' - exit 1 -fi -MATCH_TYPE=${MATCH_TYPE:--E} +# the regular expression :-) +URL_RE='(http|ftp|git|bzr)s?(\+ssh)?://[].:[[:alnum:]-]+/[-[:alnum:]/_.?&#]+[-[:alnum:]/_?&#]' # check if command was passed if [[ $# == 0 ]]; then @@ -43,29 +37,28 @@ if [[ $#P == 2 ]]; then sl_args=( -p ${P[2]} ) else - sl_args=( -p 'select item' ) + sl_args=( -p 'open url' ) fi -# grep for matches in the buffer, read them into list and reverse them -typeset -a -U matches # remove duplicates -matches=( ${(fOa)"$( tmux save-buffer - | grep $MATCH_TYPE -oe $MATCH_RE )"} ) +# grep for urls in the buffer, read them into list and reverse them +urls=( ${(fOa)"$( tmux save-buffer - | egrep -o $URL_RE )"} ) # print error if none was found -if [[ -z "$matches" ]]; then - echo "no matches found!" +if [[ -z "$urls" ]]; then + echo "no URLs found!" read -t 1 -q # wait for any keypress, up to 1 sec exit fi # display menu and print result -print -rl -- $matches | slmenu $sl_args -l $(($LINES-2)) | read match +print -rl -- $urls | slmenu $sl_args -l $(($LINES-2)) | read url # exit on canceled -[[ -z "$match" ]] && exit +[[ -z "$url" ]] && exit # execute command depending on --append flag if (($#A)); then - $cmd $match + $cmd $url else - print -r -- $match | $cmd + print -r -- $url | $cmd fi === removed file 'tmux-buffer-urls' --- tmux-buffer-urls 2012-07-29 20:30:05 +0000 +++ tmux-buffer-urls 1970-01-01 00:00:00 +0000 @@ -1,4 +0,0 @@ -#!/bin/zsh -export MATCH_RE -MATCH_RE='(http|ftp|git|bzr)s?(\+ssh)?://[].:[[:alnum:]-]+/[-[:alnum:]/_.?&#]+[-[:alnum:]/_?&#]' -exec tmux-buffer-slmenu "$@"