From: PHO Date: Sat, 20 Apr 2024 04:29:29 +0000 (+0900) Subject: Initial commit X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=HEAD;p=zsh-pkgsrc.git Initial commit --- 330584fbbed302dbe5ac7103f744950040a64956 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4b27fa5 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +DESTDIR=${HOME}/.zfunc + +.PHONY: all +all: + +.PHONY: install +install: + for f in pcd psd _pcd; do \ + install -m 644 "$${f}" "${DESTDIR}/"; \ + done diff --git a/_pcd b/_pcd new file mode 100644 index 0000000..0831461 --- /dev/null +++ b/_pcd @@ -0,0 +1,31 @@ +#compdef pcd psd + +local pkgsrcdir +if [[ -n "${PKGSRCDIR}" ]]; then + pkgsrcdir="${PKGSRCDIR}" +else + local -a candidates=( + "/usr/pkgsrc" + "/opt/pkgsrc" + ) + + local dir + for dir in "${candidates[@]}"; do + if [[ -d "$dir" ]]; then + pkgsrcdir="$dir" + break + fi + done + + if [[ -z "$pkgsrcdir" ]]; then + echo >&2 "PKGSRCDIR not detected" + return 1 + fi +fi + +_arguments '1:directory:_files -/ -W '"$pkgsrcdir" + +# Local Variables: +# mode: sh +# sh-shell: zsh +# End: diff --git a/pcd b/pcd new file mode 100644 index 0000000..bfcb226 --- /dev/null +++ b/pcd @@ -0,0 +1,39 @@ +local pkgpath +if (( $# == 1 )); then + pkgpath="$1" +else + echo >&2 "Usage: $0 PATH" + echo >&2 + echo >&2 "pcd stands for \"pkgsrc cd\", alias to cd \${PKGSRCDIR}/\${PATH}" + return 1 +fi + +local pkgsrcdir +if [[ -n "${PKGSRCDIR}" ]]; then + pkgsrcdir="${PKGSRCDIR}" +else + local -a candidates=( + "/usr/pkgsrc" + "/opt/pkgsrc" + ) + + local dir + for dir in "${candidates[@]}"; do + if [[ -d "$dir" ]]; then + pkgsrcdir="$dir" + break + fi + done + + if [[ -z "$pkgsrcdir" ]]; then + echo >&2 "PKGSRCDIR not detected" + return 1 + fi +fi + +cd "${pkgsrcdir}/${pkgpath}" + +# Local Variables: +# mode: sh +# sh-shell: zsh +# End: diff --git a/psd b/psd new file mode 100644 index 0000000..8b0d783 --- /dev/null +++ b/psd @@ -0,0 +1,39 @@ +local pkgpath +if (( $# == 1 )); then + pkgpath="$1" +else + echo >&2 "Usage: $0 PATH" + echo >&2 + echo >&2 "psd stands for \"pkgsrc pushd\", alias to pushd \${PKGSRCDIR}/\${PATH}" + return 1 +fi + +local pkgsrcdir +if [[ -n "${PKGSRCDIR}" ]]; then + pkgsrcdir="${PKGSRCDIR}" +else + local -a candidates=( + "/usr/pkgsrc" + "/opt/pkgsrc" + ) + + local dir + for dir in "${candidates[@]}"; do + if [[ -d "$dir" ]]; then + pkgsrcdir="$dir" + break + fi + done + + if [[ -z "$pkgsrcdir" ]]; then + echo >&2 "PKGSRCDIR not detected" + return 1 + fi +fi + +pushd "${pkgsrcdir}/${pkgpath}" + +# Local Variables: +# mode: sh +# sh-shell: zsh +# End: