-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.bash
58 lines (51 loc) · 1.21 KB
/
init.bash
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
if [[ $(uname) == 'Darwin' ]]; then
if [[ $(uname -m) == 'arm64' ]]; then
# assume we are using emacs-plus
EMACS=/opt/homebrew/bin/emacs
EMACS_BIN=/opt/homebrew/bin/emacsclient
else
EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs
alias emacs="$EMACS"
EMACS_BIN=/Applications/Emacs.app/Contents/MacOS/bin
fi
# provides emacsclient
export PATH=$EMACS_BIN:$PATH
else
EMACS=$(readlink -f emacs)
fi
edaemon(){
rm -f ~/.emacs.desktop.lock ~/.emacs.d/.emacs.desktop.lock
(cd ~ && "$EMACS" --daemon)
}
ec(){
emacsclient -c "$@" &
}
enw(){
emacsclient -nw "$@"
}
e(){
# open file in an existing server process
re='^[0-9]+$'
if [[ $2 =~ $re ]]; then
emacsclient -n +$2:0 $1
else
emacsclient -n "$@"
fi
}
ef () {
if [[ -z $1 ]]; then
echo "Use fzf to select file matching pattern and open in emacs"
echo "usage: $0 find-pattern [grep-pattern]"
return
fi
if [[ -z $2 ]]; then
fname="$(fd -t file "$1" | fzf --exact)"
else
fname="$(fd -t file "$1" \
| xargs grep -l "$2" \
| fzf --exact --preview "grep --color=always -n -C 5 "$2" {}")"
fi
if [[ ! -z "$fname" ]]; then
e "$fname"
fi
}