]> gitweb @ CieloNegro.org - zsh-pkgsrc.git/commitdiff
Initial commit master
authorPHO <pho@cielonegro.org>
Sat, 20 Apr 2024 04:29:29 +0000 (13:29 +0900)
committerPHO <pho@cielonegro.org>
Sat, 20 Apr 2024 04:29:29 +0000 (13:29 +0900)
Makefile [new file with mode: 0644]
_pcd [new file with mode: 0644]
pcd [new file with mode: 0644]
psd [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
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 (file)
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 (file)
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: