blob: 92761268ed424f1ed24367421aa8f72375d1adc9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
|