forked from sampson-chen/sack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathF
More file actions
executable file
·39 lines (35 loc) · 1.1 KB
/
F
File metadata and controls
executable file
·39 lines (35 loc) · 1.1 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
#!/bin/bash
# Editor: if SACK_EDITOR is not defined, take the default editor.
if [ -n "${SACK_EDITOR}" ]; then
editor=$SACK_EDITOR
else
# shellcheck disable=SC2153
editor=$EDITOR
fi
# Sack shortcut file. '$XDG_CACHE_DIR/sack/sack_shortcuts' if the variable SACK_SHORTCUT is not
# defined.
if [ -n "${SACK_SHORTCUT}" ]; then
sack_shortcutfile=$SACK_SHORTCUT
else
sack_shortcutfile="${XDG_CACHE_DIR:-${HOME}/.cache}/sack/sack_shortcuts"
fi
# Get the line number and the file name
_sack_line=$(sed -n "$1p" < "$sack_shortcutfile")
_lineno=$(echo "$_sack_line" | awk '{ print $1 }')
_fname=$(echo "$_sack_line" | awk '{ print $2 }')
if [ -f "$sack_shortcutfile" ]; then
# SublimeText
if [[ "$editor" =~ 'subl' ]]; then
subl "$_fname:$_lineno"
# VSCode
elif [[ "$editor" =~ 'code' ]]; then
$editor --goto "${_fname}:${_lineno}"
# Emacs & Vim
else
$editor +"$_lineno" "$_fname"
fi
else
echo "Sack shortcuts file '$XDG_CACHE_DIR/sack_shortcuts' not found."
echo "Please define the env. variable SACK_SHORTCUT or check if the file exist."
exit 0
fi