Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds command line flag to use previously stored settings #103

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 150 additions & 102 deletions numix-folders
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
# If not, see <http://www.gnu.org/licenses/>.

# Allows timeout when launched via 'Run in Terminal'

function sucess() { sleep 3; exit 0; }
function gerror() { sleep 5; exit 1; }

if [ -z "$1" ]; then
:
runmode=0
else
case "$1" in
-c|--colours)
Expand Down Expand Up @@ -56,8 +57,11 @@ else
"\rUsage: numix-folders [OPTION]\n" \
"\r -c, --colours \t List of available colours.\n" \
"\r -s, --styles \t\t List of available styles.\n" \
"\r -h, --help \t\t Displays this help menu."
"\r -h, --help \t\t Displays this help menu.\n"\
"\r -p, --prev \t\t Use previous settings."
sucess ;;
-p|--prev)
runmode=1;;
*)
echo -e \
"numix-folders: invalid option -- '$1'\n" \
Expand All @@ -67,6 +71,13 @@ else
fi

cuser="${SUDO_USER:-$USER}"

config_file=/home/"$cuser"/.config/numix-folders
if [ ! -f "$config_file" ];then
touch "$config_file"
runmode=0
fi

if [ -d /home/"$cuser"/.local/share/icons/Numix/ ]; then
dir=/home/"$cuser"/.local/share/icons
elif [ -d /home/"$cuser"/.icons/Numix ]; then
Expand All @@ -87,109 +98,140 @@ else
gerror
fi

read -p "Which folder style do you want? " answer
if [ -z "$answer" ]; then
style="0"
elif [ -d styles/"$answer" ]; then
style="$answer"
else
echo -e \
"Oops! You've chosen an invalid style number.\n" \
"\rRun 'numix-folders --styles' for an option list."
gerror
fi

read -p "Which folder colour do you want? " answer
answer="$(tr '[:upper:]' '[:lower:]' <<< "$answer")" #convert answer to lowercase
if [ -z "$answer" ]; then
colour="default"
elif [ "$answer" == "custom" ] || [[ $answer == "style"[1-6] ]]; then
colour1="000000"
colour2="000000"
colour3="000000"
colour="custom"

styledef=$style
if [[ $answer == "style"[1-6] ]]; then
styledef=${answer#"style"}
fi
case "$styledef" in
"1")
col1def="c4905e"
col2def="b07f51"
col3def="f9f9f9"
;;
"2")
col1def="e8b07f"
col2def="9e7757"
col3def="9e7757"
;;
"3")
col1def="f2bb64"
col2def="ea9036"
col3def="b58c4b"
;;
"4")
col1def="f5c14e"
col2def="e9a439"
col3def="c79d41"
;;
"5")
col1def="ffb300"
col2def="f57c00"
col3def="fff8e1"
;;
"6" | "0")
col1def="ffa726"
col2def="ef6c00"
col3def="b17621"
;;
esac

function checkhex() {
if ! [[ $1 =~ ^[0-9A-Fa-f]{6}$ ]]; then
echo -e \
"Oops! The colour: $1 is an invalid hex value.\n" \
"\rBe sure to use valid hex values with six digits (e.g. 000000)."
gerror
fi
}

if [[ $answer == "custom" ]]; then
if grep -q "replacecolour1" styles/"${style}"/Numix/48x48/places/custom-folder-video.svg; then
read -p "Choose primary colour in hex notation (default: $col1def): " colour1
if [ -z "$colour1" ]; then
colour1=$col1def
exitloop=0
until [ "$exitloop" -eq 1 ]; do
case $runmode in
1)
echo "Trying to use previously stored settings"
style=`sed -n 1p $config_file`
colour=`sed -n 2p $config_file`
colour1=`sed -n 3p $config_file`
colour2=`sed -n 4p $config_file`
colour3=`sed -n 5p $config_file`
if [[ "$style" -gt 6 || "$style" -lt 1 ]] || [[ -z $colour ]]; then
exitloop=0
runmode=0
echo "There were errors in your config file!"
continue
fi
checkhex $colour1
fi
if grep -q "replacecolour2" styles/"${style}"/Numix/48x48/places/custom-folder-video.svg; then
read -p "Choose secondary colour in hex notation (default: $col2def): " colour2
if [ -z "$colour2" ]; then
colour2=$col2def
if [ "$colour" == "custom" ]; then
if ! [[ "$colour1" =~ ^[0-9A-Fa-f]{6}$ ]] || ! [[ "$colour2" =~ ^[0-9A-Fa-f]{6}$ ]] || ! [[ "$colour3" =~ ^[0-9A-Fa-f]{6}$ ]]; then
exitloop=0
runmode=0
echo "There were errors in your config file!"
continue
fi
fi
checkhex $colour2
fi
if grep -q "replacecolour3" styles/"${style}"/Numix/48x48/places/custom-folder-video.svg; then
read -p "Choose symbol colour in hex notation (default: $col3def): " colour3
if [ -z "$colour3" ]; then
colour3=$col3def
exitloop=1
;;
0)
read -p "Which folder style do you want? " answer
if [ -z "$answer" ]; then
style="0"
elif [ -d styles/"$answer" ]; then
style="$answer"
else
echo -e \
"Oops! You've chosen an invalid style number.\n" \
"\rRun 'numix-folders --styles' for an option list."
gerror
fi
checkhex $colour3
fi
else
colour1=$col1def
colour2=$col2def
colour3=$col3def
fi
elif [ -d colours/"$answer" ]; then
colour="$answer"
else
echo -e \
"Oops! You've chosen an invalid colour.\n" \
"\rRun 'numix-folders --colours' for an option list."
gerror
fi

read -p "Which folder colour do you want? " answer
answer="$(tr '[:upper:]' '[:lower:]' <<< "$answer")" #convert answer to lowercase
colour1="000000"
colour2="000000"
colour3="000000"
if [ -z "$answer" ]; then
colour="default"
elif [ "$answer" == "custom" ] || [[ $answer == "style"[1-6] ]]; then
colour="custom"

styledef=$style
if [[ $answer == "style"[1-6] ]]; then
styledef=${answer#"style"}
fi
case "$styledef" in
"1")
col1def="c4905e"
col2def="b07f51"
col3def="f9f9f9"
;;
"2")
col1def="e8b07f"
col2def="9e7757"
col3def="9e7757"
;;
"3")
col1def="f2bb64"
col2def="ea9036"
col3def="b58c4b"
;;
"4")
col1def="f5c14e"
col2def="e9a439"
col3def="c79d41"
;;
"5")
col1def="ffb300"
col2def="f57c00"
col3def="fff8e1"
;;
"6" | "0")
col1def="ffa726"
col2def="ef6c00"
col3def="b17621"
;;
esac

function checkhex() {
if ! [[ $1 =~ ^[0-9A-Fa-f]{6}$ ]]; then
echo -e \
"Oops! The colour: $1 is an invalid hex value.\n" \
"\rBe sure to use valid hex values with six digits (e.g. 000000)."
gerror
fi
}

if [[ $answer == "custom" ]]; then
if grep -q "replacecolour1" styles/"${style}"/Numix/48x48/places/custom-folder-video.svg; then
read -p "Choose primary colour in hex notation (default: $col1def): " colour1
if [ -z "$colour1" ]; then
colour1=$col1def
fi
checkhex $colour1
fi
if grep -q "replacecolour2" styles/"${style}"/Numix/48x48/places/custom-folder-video.svg; then
read -p "Choose secondary colour in hex notation (default: $col2def): " colour2
if [ -z "$colour2" ]; then
colour2=$col2def
fi
checkhex $colour2
fi
if grep -q "replacecolour3" styles/"${style}"/Numix/48x48/places/custom-folder-video.svg; then
read -p "Choose symbol colour in hex notation (default: $col3def): " colour3
if [ -z "$colour3" ]; then
colour3=$col3def
fi
checkhex $colour3
fi
else
colour1=$col1def
colour2=$col2def
colour3=$col3def
fi
elif [ -d colours/"$answer" ]; then
colour="$answer"
else
echo -e \
"Oops! You've chosen an invalid colour.\n" \
"\rRun 'numix-folders --colours' for an option list."
gerror
fi
exitloop=1
;;
esac
done

cp -rf styles/"${style}"/Numix/* "${dir}"/Numix/

Expand Down Expand Up @@ -228,4 +270,10 @@ if [ -d "${dir}"/Numix-Square/ ]; then
fi

echo "Folder change complete!"
echo "$style" > "$config_file"
echo "$colour" >> "$config_file"
echo "$colour1" >> "$config_file"
echo "$colour2" >> "$config_file"
echo "$colour3" >> "$config_file"
chown -R "$cuser" "$config_file"
sucess