#!/bin/sh # Add a cd alias to the $ORGD_CDALIAS_PATH file. # Checks the path is valid first before adding it, and that alias less than # seven characters as per the requirements. # Usage: cdadd alias $HOME/target/directory # Pass -p to disable the check for a valid path. dir="$(orgdresolv ORGD_SD_PATH)" path="$(orgdresolv ORGD_CDALIAS_PATH)" alias="$1" target="$2" # Ensure that $ORGD_CDALIAS_PATH exists mkdir -p "$dir" touch "$path" # Check alias less than eight characters. [ ${#alias} -gt 8 ] && \ echo "Alias ($alias) must be less than eight characters long." && \ exit # Check $target is a valid path. if [ ! -d "$target" ] ; then if ! isflag '-p' "$@" ; then echo "Target ($target) is not a valid directory" && \ exit fi fi # Check if alias already exists as a cd alias, grep with tab to not match part # of existing alias. awk ' { print $1 } ' $path | grep -q "$alias " && \ echo "The alias ($alias) already exists." && \ exit echo "$alias $target" >> $path