-
Notifications
You must be signed in to change notification settings - Fork 0
/
subl
44 lines (37 loc) · 1005 Bytes
/
subl
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
#!/bin/bash
set -euo pipefail
SUBLWSL_CREATE_NOEXIST=${SUBLWSL_CREATE_NOEXIST:-true}
SUBLWSL_QUIET=${SUBLWSL_QUIET:-true}
is_true() {
local var="$1"
case $var in
yes|y|true|t|on|1) return 0 ;;
esac
return 1
}
args=()
paths=()
for arg in "$@"; do
# Save arguments with leading "-". Note: we can't open files with a leading "-"
if [[ "$arg" == -* ]]; then
args+=("$arg")
else
paths+=("$arg")
fi
done
# Convert paths to win paths
winpaths=()
for path in "${paths[@]}"; do
if is_true "$SUBLWSL_CREATE_NOEXIST" && [[ ! -e "$path" ]]; then
is_true "$SUBLWSL_QUIET" || echo "Creating $path"
touch "$path"
fi
canpath=$(readlink -f "$path")
winpath=$(wslpath -w "$canpath")
winpaths+=("$winpath")
done
if ! is_true "$SUBLWSL_QUIET" && [[ -n "${paths[@]}" ]]; then
echo "Editing ${paths[@]}"
echo "Windows path is ${winpaths[@]}"
fi
/mnt/c/Program\ Files/Sublime\ Text/subl.exe "${args[@]}" "${winpaths[@]}"