functions/xhashd
author Mikael Berthe <mikael@lilotux.net>
Sat, 02 Oct 2021 10:49:57 +0200
changeset 52 1f3d221e1770
parent 22 f84d194b7d99
permissions -rw-r--r--
vi mode: Add missing beginning-of-line key bindings Reorder bindings so they are (hopefully) more readable...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
### xhashd(): check for directory, then create hash -d
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
# Copied and slightly modified from Franck Terbeck zsh configuration.
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
# https://dev.0x50.de/projects/ftzsh/repository
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
local key val com
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
if (( ${#argv} == 0 )) ; then
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
    printf 'xhashd(): Missing argument.\n'
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
    return 1
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
fi
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
if (( ${#argv} > 1 )) ; then
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
    printf 'xhashd(): Too many arguments %s\n' "${#argv}"
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
    return 1
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
fi
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
key="${1%%\=*}" ;  val="${1#*\=}"
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
val=${val/#\~\//$HOME/}
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
[[ -d ${val} ]] && hash -d -- "${key}=${val}"
f84d194b7d99 Add ft's xhashd function
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
return 0