Skip to content

Instantly share code, notes, and snippets.

@baku89
Last active March 21, 2016 15:44
Show Gist options
  • Select an option

  • Save baku89/071b52a38d0376b830c5 to your computer and use it in GitHub Desktop.

Select an option

Save baku89/071b52a38d0376b830c5 to your computer and use it in GitHub Desktop.
My work-related shell scripts & zsh configs
WORKROOT=${HOME}/Works
WORKDIR=${WORKROOT}/$(date +"%Y")
cdw() {
cd $(dirname ${WORKDIR}) > /dev/null
if [ $# -eq 1 ]; then
matched=$(find . -name "*$1*" -mindepth 2 -maxdepth 2)
count=$(echo $matched | wc -l)
if [ $count -eq 0 ]; then
echo "No project found"
else
cd $(echo $matched | head -n 1) > /dev/null
fi
fi
}
ow() {
if [ $# -eq 1 ]; then
open $(cdw $1; pwd)
fi
}

my work-related directries consist like below:

WORKROOT
 └ year (YYYY)
  ├ 00_everydays
  ├ 01_aaaa
  ├ 02_bbbb

To move to each project diretory or sync via Dropbox quickly, I've written some set of shell commands.

  • cdw [proj] to change the present working directory to project root
  • ow [proj] to open project root in Finder
  • syncw [dirname] to sync specified directory via Dropbox and replace with symbolic link
#!/bin/zsh
if [ $# -ne 2 ]; then
exit 1
fi
mkdir -p $(dirname ${2})
mv $1 $2
ln -s $2 $1
#!/bin/zsh
relpath() {
python -c 'import os.path, sys;\
print os.path.relpath(sys.argv[1],sys.argv[2])' "$1" "${2-$PWD}"
}
# ====================================
# 1. retrieve paths
if [ $# -eq 1 ]; then
destPath=$(cd ${1}; pwd)
else
destPath=$(pwd)
fi
relPath=$(relpath "$destPath" "$WORKROOT")
syncPath=${HOME}/Dropbox/Works/${relPath}
# ====================================
# 2. confirm
echo "${destPath}\n -> ${syncPath}\n Proceed? [Y/n]"
read ANSWER
case $ANSWER in
"" | "Y" | "y" | "yes" | "Yes" | "YES" );;
* ) return 1;;
esac
# ====================================
# 3. execute
lnk ${destPath} ${syncPath}
#========================================
# .zshrc
WORKROOT=${HOME}/Works
WORKDIR=${WORKROOT}/$(date +"%Y")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment