-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-editor
More file actions
executable file
·49 lines (40 loc) · 820 Bytes
/
git-editor
File metadata and controls
executable file
·49 lines (40 loc) · 820 Bytes
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
#!/bin/sh
###
### An editor wrapper that intelligently chooses between terminal and GUI editors.
###
main() {
try_exec_tty nvim "$@"
try_exec_gui code --wait "$@"
try_exec_gui codium --wait "$@"
try_exec_gui zed --wait "$@"
try_exec_gui subl --wait "$@"
try_exec_tty vim "$@"
try_exec_tty vi "$@"
echo "Error: No editor found"
exit 1
}
try_exec() {
command_name="$1"
shift
if ! command -v "$command_name" >/dev/null 2>&1; then
return
fi
exec "$command_name" "$@"
}
try_exec_tty() {
if [ "$HAS_TTY" != "1" ]; then
return
fi
try_exec "$@"
}
try_exec_gui() {
try_exec "$@"
}
set -e # Exit immediately if any command returns non-zero status
set -u # Treat unset variables as errors
HAS_TTY=0
if [ -r /dev/tty ] && [ -w /dev/tty ]; then
HAS_TTY=1
exec </dev/tty >/dev/tty 2>&1
fi
main "$@"