From 7d2f3407582bad5db844e47db24d1f8ff2e21c1f Mon Sep 17 00:00:00 2001 From: Adolfo Perez Alvarez Date: Wed, 25 May 2022 16:04:40 +0200 Subject: [PATCH] Directory aliases and quick directory navigation `diralias` allows you to map a symbolic name to an absolute path. `j` takes an alias name, and jumps (cd) to it. --- diralias | 35 +++++++++++++++++++++++++++++++++++ j | 14 ++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 diralias create mode 100644 j diff --git a/diralias b/diralias new file mode 100644 index 0000000..ccfe528 --- /dev/null +++ b/diralias @@ -0,0 +1,35 @@ +#!/bin/ksh +diralias() +{ + typeset -i i + case $# in + 0) + let i=0 + while (( i < ${#DIRALIASNAM[@]} )) + do + printf "%s\t%s\n" ${DIRALIASNAM[i]} "${DIRALIASVAL[i]}" + let i++ + done + ;; + 1) + let i=0 + while [[ i -lt ${#DIRALIASNAM[@]} && $1 != ${DIRALIASNAM[i]} ]] + do + let i++ + done + (( i == ${#DIRALIASNAM[@]} )) && echo $1 || echo ${DIRALIASVAL[i]} + ;; + 2) + let i=0 + while [[ i -lt ${#DIRALIASNAM[@]} && $1 != ${DIRALIASNAM[i]} ]] + do + let i++ + done + DIRALIASNAM[i]=$1 + DIRALIASVAL[i]="$2" + ;; + *) + exit 64 + ;; + esac +} diff --git a/j b/j new file mode 100644 index 0000000..b7edd16 --- /dev/null +++ b/j @@ -0,0 +1,14 @@ +#!/bin/ksh +j() +{ + local da + da=$(diralias $1) + if echo $da | grep '^!' >/dev/null + then + if ! da=$(eval $(echo "$da" | sed 's/^!//') 2>/dev/null) + then + return 65 + fi + fi + 'cd' "$da" +}