diff options
author | Cody Hiar <codyfh@gmail.com> | 2019-04-25 11:14:30 -0600 |
---|---|---|
committer | Cody Hiar <codyfh@gmail.com> | 2019-04-25 11:14:45 -0600 |
commit | b5efb94ed8e3cb15f489cdabe4fe2cbc00af1df9 (patch) | |
tree | dd1aea92a9968c810b65e04f3cc3a648abfa00c4 /scripts/url_search.sh | |
parent | 114eea36cc94e6ece7e456d7839f1af9e37de451 (diff) |
Initial work on url copy
Diffstat (limited to 'scripts/url_search.sh')
-rwxr-xr-x | scripts/url_search.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/url_search.sh b/scripts/url_search.sh new file mode 100755 index 0000000..9276126 --- /dev/null +++ b/scripts/url_search.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# vim: set filetype=sh +# +# Author: Cody Hiar +# Date: 2019-04-25 +# +# Description: Search buffer for url results +# +# Set options: +# e: Stop script if command fails +# u: Stop script if unset variable is referenced +# x: Debug, print commands as they are executed +# o pipefail: If any command in a pipeline fails it all fails +# +# IFS: Internal Field Separator +set -euo pipefail +IFS=$'\n\t' + +# Colors for printing +G='\e[0;32m' # Green +LG='\e[0;37m' # Light Gray +C='\e[0;36m' # Cyan +NC='\e[0m' # No Color + +# Immutable globals +readonly ARGS=( "$@" ) +readonly NUM_ARGS="$#" +readonly PROGNAME=$(basename "$0") +readonly BUFFER='/tmp/tmuxcopy.log' +POSITION=1 + +cleanup() { + rm -rf "$BUFFER" +} + +create_buffer() { + touch "$BUFFER" + trap cleanup EXIT +} + +capture_pane() { + tmux capture-pane -S -9000000 -p > "$BUFFER" +} + +find_urls() { + perl -wnl -e '/https?\:\/\/[^\s]+[\/\w]/ and print $&' "$BUFFER" +} + +# Main loop of program +main() { + create_buffer + capture_pane + URL=$(find_urls | tail -n "$POSITION") + tmux copy-mode ; tmux send -X search-backward $URL +} +main |