Created
December 3, 2010 00:19
-
-
Save docwhat/726361 to your computer and use it in GitHub Desktop.
A simple thingy for Andrew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This sets up the functions needed to make this work. | |
DG_DIR="${HOME}/.drewgo" | |
# Shows the list of saved directories. | |
function dg_show { | |
if [[ -r "${DG_DIR}/directories" ]]; then | |
cat "${DG_DIR}/directories" | |
else | |
echo "You haven't added anything yet." | |
return | |
fi | |
} | |
# Goes to the directory and performs any commands. | |
function dg_go { | |
local name="${1}" | |
local dir='' | |
if [[ -z "${name}" ]]; then | |
echo "You need to specify a name." | |
return | |
fi | |
if [[ ! -r "${DG_DIR}/directories" ]]; then | |
echo "You haven't added anything yet." | |
return | |
fi | |
local IFS=$'\n' | |
for line in $(cat "${DG_DIR}/directories"); do | |
IFS=$'\t' | |
local -a line=(${line}) | |
if [[ "${line[0]}" = "${name}" ]]; then | |
dir="${line[1]}" | |
fi | |
done | |
if [[ ! -n "${dir}" ]]; then | |
echo "Couldn't find '${name}'" | |
return | |
fi | |
if [[ ! -d "${dir}" ]]; then | |
echo "No such directory: ${dir}" | |
fi | |
cd "${dir}" | |
if [[ -r .dgrc ]]; then | |
source .dgrc | |
fi | |
} | |
# Adds the current directory to your list. | |
function dg_add { | |
local name="${1:-}" | |
if [[ -z "${name}" ]]; then | |
echo "You need to specify a name." | |
return | |
fi | |
if [[ ! -d "${DG_DIR}" ]]; then | |
mkdir -p "${DG_DIR}" | |
fi | |
local dir="$(pwd -L)" | |
echo "${name}"$'\t'"${dir}" >> "${DG_DIR}/directories" | |
echo "Added ${name} for ${dir}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment