-
Notifications
You must be signed in to change notification settings - Fork 4
/
helix-wezterm.sh
executable file
·127 lines (118 loc) · 4.06 KB
/
helix-wezterm.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
set -x
status_line=$(wezterm cli get-text | rg -e "(?:NOR\s+|NORMAL|INS\s+|INSERT|SEL\s+|SELECT)\s+[\x{2800}-\x{28FF}]*\s+(\S*)\s[^│]* (\d+):*.*" -o --replace '$1 $2')
filename=$(echo $status_line | awk '{ print $1}')
line_number=$(echo $status_line | awk '{ print $2}')
split_pane_down() {
bottom_pane_id=$(wezterm cli get-pane-direction down)
if [ -z "${bottom_pane_id}" ]; then
bottom_pane_id=$(wezterm cli split-pane)
fi
wezterm cli activate-pane-direction --pane-id $bottom_pane_id down
send_to_bottom_pane="wezterm cli send-text --pane-id $bottom_pane_id --no-paste"
program=$(wezterm cli list | awk -v pane_id="$bottom_pane_id" '$3==pane_id { print $6 }')
if [ "$program" = "lazygit" ]; then
echo "q" | $send_to_bottom_pane
fi
}
pwd=$(PWD)
basedir=$(dirname "$filename")
basename=$(basename "$filename")
basename_without_extension="${basename%.*}"
extension="${filename##*.}"
case "$1" in
"blame")
split_pane_down
echo "cd $pwd; tig blame $filename +$line_number" | $send_to_bottom_pane
;;
"check")
split_pane_down
case "$extension" in
"rs")
run_command="cd $pwd/$(echo $filename | sed 's|src/.*$||'); cargo check; if [ \$status = 0 ]; wezterm cli activate-pane-direction up; end;"
;;
esac
echo "$run_command" | $send_to_bottom_pane
;;
"explorer")
left_pane_id=$(wezterm cli get-pane-direction left)
if [ -z "${left_pane_id}" ]; then
left_pane_id=$(wezterm cli split-pane --left --percent 20)
fi
left_program=$(wezterm cli list | awk -v pane_id="$left_pane_id" '$3==pane_id { print $6 }')
if [ "$left_program" != "br" ]; then
echo "br" | wezterm cli send-text --pane-id $left_pane_id --no-paste
fi
wezterm cli activate-pane-direction left
;;
"fzf")
split_pane_down
echo "cd $pwd; hx-fzf.sh \$(rg --line-number --column --no-heading --smart-case . | fzf --delimiter : --preview 'bat --style=full --color=always --highlight-line {2} {1}' --preview-window '~3,+{2}+3/2' | awk '{ print \$1 }' | cut -d: -f1,2,3)" | $send_to_bottom_pane
;;
"howdoi")
split_pane_down
echo "howdoi -c `pbpaste`" | $send_to_bottom_pane
;;
"lazygit")
split_pane_down
program=$(wezterm cli list | awk -v pane_id="$pane_id" '$3==pane_id { print $6 }')
if [ "$program" = "lazygit" ]; then
wezterm cli activate-pane-direction down
else
echo "lazygit" | $send_to_bottom_pane
fi
;;
"open")
gh browse $filename:$line_number
;;
"run")
split_pane_down
case "$extension" in
"c")
run_command="clang -lcmocka -lmpfr -Wall -g -O1 $filename -o $basedir/$basename_without_extension && $basedir/$basename_without_extension"
;;
"go")
run_command="go run $basedir/*.go"
;;
"md")
run_command="mdcat -p $filename"
;;
"rkt"|"scm")
run_command="racket $filename"
;;
"rs")
run_command="cd $pwd/$(echo $filename | sed 's|src/.*$||'); cargo run; if [ \$status = 0 ]; wezterm cli activate-pane-direction up; end"
;;
"sh")
run_command="sh $filename"
;;
esac
echo "$run_command" | $send_to_bottom_pane
;;
"test_all")
split_pane_down
case "$extension" in
"go")
run_command="go test -v ./...; if [ \$status = 0 ]; wezterm cli activate-pane-direction up; end;"
;;
"rs")
run_command="cd $pwd/$(echo $filename | sed 's|src/.*$||'); cargo test; if [ \$status = 0 ]; wezterm cli activate-pane-direction up; end;"
;;
esac
echo "$run_command" | $send_to_bottom_pane
;;
"test_single")
test_name=$(head -$line_number $filename | tail -1 | sed -n 's/^.*fn \([^ ]*\)().*$/\1/p')
split_pane_down
case "$extension" in
"rs")
run_command="cd $pwd/$(echo $filename | sed 's|src/.*$||'); cargo test $test_name; if [ \$status = 0 ]; wezterm cli activate-pane-direction up; end;"
;;
esac
echo "$run_command" | $send_to_bottom_pane
;;
"tgpt")
split_pane_down
echo "tgpt '`pbpaste`'" | $send_to_bottom_pane
;;
esac