Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 91 lines (74 sloc) 1.555 kb
#!/bin/bash
# tput can get cols
# printf can pad strings
APP=$( basename $0 )
COLS=$( tput cols )
C1=$( tput setaf 1 ) # red
C2=$( tput setaf 2 ) # green
C4=$( tput setaf 4 ) # blue
R=$( tput sgr0 )
# $1 is target.
# $2 is name.
function create_link()
{
echo -n "Linking $C2$2$R -> $C4$1$R "
#printf "%-80s" "Linking $C2$2$R -> $C4$1$R "
if [ -e $2 ];
then
echo "$C1[FAIL] File exists.$R"
return
fi
# redirect stdout and stderr
/bin/ln -s $1 $2
if (( $? )) ;
then
echo "$C1[FAIL] Error creating link.$R"
else
echo "$C2[DONE]$R"
fi
}
# $1 link to remove
function remove_link()
{
echo -n "Unlinking $C2$2$R -> $C4$1$R "
if [ ! -h $2 ];
then
echo "$C1[FAIL] Not a link.$R"
return
fi
rm $2
if (( $? )) ;
then
echo "$C1[FAIL] Error removing link.$R"
else
echo "$C2[DONE]$R"
fi
}
# $1 command
function apply_command()
{
for FILE in *
do
MATCH=$( head -n 3 $FILE | grep -m 1 '[[:space:]]\+\[cmgr\]\(.*\)' )
if [[ "$MATCH" =~ [[:space:]]\[cmgr\][[:space:]](.*) ]]
then
$1 $PWD/$FILE $HOME/${BASH_REMATCH[1]}
fi
done
}
# main
if [ "$1" == "link" ];
then
apply_command create_link
elif [ "$1" == "unlink" ];
then
apply_command remove_link
elif [ "$1" == "update" ];
then
echo "Updating, call git, etc."
else
echo "$APP - Config Manager v0.1"
echo "usage: $APP link"
echo " $APP unlink"
echo " $APP update"
fi
Jump to Line
Something went wrong with that request. Please try again.