-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshell.go
67 lines (62 loc) · 1.69 KB
/
shell.go
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
package main
// ZshHook will setup a zshell hook to run and update based on commands
func ZshHook() string {
return `
_fasder_preexec() {
{ eval "fasder --proc $(fasder --sanitize $2)"; } >> /dev/null 2>&1
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec _fasder_preexec
`
}
func Aliases() string {
return `
alias a='fasder'
alias d='fasder -d'
alias f='fasder -f'
alias v='fasder -fe $EDITOR'
j() {
if [ "$#" -gt 0 ]; then
cd "$(fasder -de 'printf %s' "$@")" || return 1
else
cd -
fi
}
`
}
func fzfAliases() string {
return `
jj () {
local selection
selection=$(fasder -Rdl "$@" | fzf -1 -0 --no-sort +m --height=10)
if [[ -n "$selection" ]]; then
echo "Selection: $selection"
echo "$selection" | xargs -r fasder --add
cd "$selection" || return 1
else
echo "No selection made"
return 1
fi
}
vv () {
local selection
# Get the selection from fasder and fzf
selection=$(fasder -Rfl "$@" | fzf -1 -0 --no-sort +m --height=10)
# Check if a selection was made
if [[ -n "$selection" ]]; then
# Ensure the editor is set and handle potential issues
if [[ -z "$EDITOR" ]]; then
echo "EDITOR environment variable is not set."
return 1
fi
# Use xargs with -r to prevent running the editor if no selection
echo "Selection: $selection"
echo "$selection" | xargs -r fasder --add
echo "$selection" | xargs -r "$EDITOR"
else
echo "No selection made."
return 1
fi
}
`
}