blob: 57f1b69896a5e53836ad57ab39c6d80c46adf77d (
plain) (
blame)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 | #!/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
 |