Skip to content

Commit e67806b

Browse files
committed
zsh: Add fasd module
- _fasd_preexec() and fasd_cd are autoloadable functions - Backported some PRs from clvv/fasd - [clvv/fasd#54] Correction of newline print statement in fasd_cd - [clvv/fasd#75] fasd_cd: return 1 in case no dir was found - *Partial* [clvv/fasd#77] XDG Compliance - [clvv/fasd#99] Do not "eval" in zsh's _fasd_preexec
1 parent 9ccecfd commit e67806b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

.zsh/modules/fasd/fasd.zsh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Fasd Configuration
3+
#
4+
5+
(( $+commands[fasd] )) || return 1
6+
7+
# _fasd_config="${XDG_CONFIG_HOME:-"$HOME/.config"}/fasd/config"
8+
_FASD_DATA="${XDG_CACHE_HOME:-"$HOME/.cache"}/fasd/fasd"
9+
_fasd_cache="${XDG_CACHE_HOME:-"$HOME/.cache"}/fasd/init"
10+
_fasd_hooks="$(print zsh-{c,w}comp{,-install})"
11+
12+
### Initialize fasd
13+
14+
for dir ($_FASD_DATA $_fasd_cache) {
15+
[[ -d ${dir:h} ]] || mkdir -p ${dir:h}
16+
}
17+
18+
# Cache initialization code if needed
19+
if [[ "$commands[fasd]" -nt "$_fasd_cache" || ! -s "$_fasd_cache" ]]; then
20+
fasd --init ${=_fasd_hooks} >| "$_fasd_cache"
21+
fi
22+
source "$_fasd_cache"
23+
24+
### Aliases
25+
26+
# Standard
27+
alias a='fasd -a'
28+
alias s='fasd -si'
29+
alias sd='fasd -sid'
30+
alias sf='fasd -sif'
31+
alias d='fasd -d'
32+
alias f='fasd -f'
33+
alias z='fasd_cd -d'
34+
alias zz='fasd_cd -d -i'
35+
36+
# Extra
37+
alias v='f -e $EDITOR'
38+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ fasd --proc $(fasd --sanitize "$2") } >> "$_FASD_SINK" 2>&1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# function to execute built-in cd
2+
if [ $# -le 1 ]; then
3+
fasd "$@"
4+
else
5+
local _fasd_ret="$(fasd -e 'printf %s' "$@")"
6+
[ -z "$_fasd_ret" ] && return 1
7+
[ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf '%s\n' "$_fasd_ret"
8+
fi
9+
10+
# vim: ft=zsh

0 commit comments

Comments
 (0)