Skip to content

Commit

Permalink
zsh: Add fasd module
Browse files Browse the repository at this point in the history
  - _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
  • Loading branch information
ZeroKnight committed Oct 25, 2016
1 parent 9ccecfd commit e67806b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .zsh/modules/fasd/fasd.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Fasd Configuration
#

(( $+commands[fasd] )) || return 1

# _fasd_config="${XDG_CONFIG_HOME:-"$HOME/.config"}/fasd/config"
_FASD_DATA="${XDG_CACHE_HOME:-"$HOME/.cache"}/fasd/fasd"
_fasd_cache="${XDG_CACHE_HOME:-"$HOME/.cache"}/fasd/init"
_fasd_hooks="$(print zsh-{c,w}comp{,-install})"

### Initialize fasd

for dir ($_FASD_DATA $_fasd_cache) {
[[ -d ${dir:h} ]] || mkdir -p ${dir:h}
}

# Cache initialization code if needed
if [[ "$commands[fasd]" -nt "$_fasd_cache" || ! -s "$_fasd_cache" ]]; then
fasd --init ${=_fasd_hooks} >| "$_fasd_cache"
fi
source "$_fasd_cache"

### Aliases

# Standard
alias a='fasd -a'
alias s='fasd -si'
alias sd='fasd -sid'
alias sf='fasd -sif'
alias d='fasd -d'
alias f='fasd -f'
alias z='fasd_cd -d'
alias zz='fasd_cd -d -i'

# Extra
alias v='f -e $EDITOR'

1 change: 1 addition & 0 deletions .zsh/modules/fasd/functions/_fasd_preexec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ fasd --proc $(fasd --sanitize "$2") } >> "$_FASD_SINK" 2>&1
10 changes: 10 additions & 0 deletions .zsh/modules/fasd/functions/fasd_cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# function to execute built-in cd
if [ $# -le 1 ]; then
fasd "$@"
else
local _fasd_ret="$(fasd -e 'printf %s' "$@")"
[ -z "$_fasd_ret" ] && return 1
[ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf '%s\n' "$_fasd_ret"
fi

# vim: ft=zsh

0 comments on commit e67806b

Please sign in to comment.