-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.zsh
More file actions
executable file
·71 lines (61 loc) · 1.25 KB
/
editor.zsh
File metadata and controls
executable file
·71 lines (61 loc) · 1.25 KB
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
#!/bin/zsh
# shellcheck disable=SC2076
# shellcheck disable=SC2154
function launch-editor() {
local editor=$1
local linenum
local filename
shift
while [[ $# -gt 0 ]]; do
local arg=$1
if [[ $arg = '--line' ]]; then
linenum=$2
shift
shift
elif [[ $arg = '--file' ]]; then
filename=$2
shift
shift
elif [[ $arg =~ '^--line[= ]([0-9]+)$' ]]; then
linenum=${match[1]}
shift
elif [[ $arg =~ '^\+([0-9]+)$' ]]; then
linenum=${match[1]}
shift
elif [[ $arg =~ '^--file[= ](.+)$' ]]; then
filename=${match[1]}
shift
elif [[ $arg =~ '^(.+):([0-9]+)$' ]]; then
filename=${match[1]}
linenum=${match[2]}
shift
elif [[ -z $filename ]]; then
filename=$1
shift
elif [[ -z $linenum ]]; then
linenum=$1
shift
else
echo "Invalid editor arguments"
exit 1
fi
done
if [[ -z $filename ]]; then
echo "No filename specified"
exit 1
fi
local cmdtorun=("$editor")
if [[ -v linenum ]]; then
case $editor in
webstorm|idea)
cmdtorun+=("--line" "$linenum")
;;
*)
cmdtorun+=("+$linenum")
;;
esac
fi
cmdtorun+=("$filename")
"${cmdtorun[@]}"
}
launch-editor "$@"