Skip to content

Instantly share code, notes, and snippets.

@h-hirai
Last active December 16, 2015 00:59
Show Gist options
  • Save h-hirai/5351378 to your computer and use it in GitHub Desktop.
Save h-hirai/5351378 to your computer and use it in GitHub Desktop.
#! /bin/bash
IFS_BAK=$IFS
IFS=':'
is_include () {
l=$1
e=$2
for p in $l; do
if [ "$p" == "$e" ]; then
return 0
fi
done
return 1
}
append_head () {
l=$1
h=$2
if [ -z "$l" ]; then
echo "$h"
elif is_include "$l" "$h"; then
echo "$l"
else
echo "$h:$l"
fi
}
append_tail () {
l=$1
t=$2
if [ -z "$l" ]; then
echo "$t"
elif is_include "$l" "$t"; then
echo "$l"
else
echo "$l:$t"
fi
}
newpath=""
for p in $PATH; do
if [ -d "$p" ]; then
if echo "$p" | grep cabal > /dev/null; then
newpath=$(append_head "$newpath" "$p")
else
newpath=$(append_tail "$newpath" "$p")
fi
fi
done
echo "$newpath"
IFS=$IFS_BAK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment