refactor: Update starship.toml file path and add optional icon parameter in setup.sh
This commit is contained in:
parent
e1d8a84146
commit
f7124662d1
33
setup.sh
33
setup.sh
|
@ -13,26 +13,17 @@ usage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse command-line options
|
# Parse command-line options
|
||||||
while getopts ":i:-:" opt; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $opt in
|
key="$1"
|
||||||
i)
|
|
||||||
icon="$OPTARG"
|
case $key in
|
||||||
|
--icon)
|
||||||
|
icon="$2"
|
||||||
|
shift # past argument
|
||||||
|
shift # past value
|
||||||
;;
|
;;
|
||||||
-)
|
*)
|
||||||
case "${OPTARG}" in
|
# unknown option
|
||||||
icon=*)
|
|
||||||
icon="${OPTARG#*=}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
:)
|
|
||||||
echo "Option -$OPTARG requires an argument."
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
?)
|
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -69,14 +60,14 @@ overwrite_starship_toml() {
|
||||||
if [ -f "./terminal/starship.toml" ]; then
|
if [ -f "./terminal/starship.toml" ]; then
|
||||||
echo "Overwriting starship.toml..."
|
echo "Overwriting starship.toml..."
|
||||||
mkdir -p ~/.config/starship
|
mkdir -p ~/.config/starship
|
||||||
cp ./terminal/starship.toml ~/.config/starship.toml
|
cp ./terminal/starship.toml ~/.config/starship/starship.toml
|
||||||
|
|
||||||
# Check if icon parameter is provided
|
# Check if icon parameter is provided
|
||||||
if [ ! -z "$icon" ]; then
|
if [ ! -z "$icon" ]; then
|
||||||
echo "Adding icon [$icon](bg:color_purple fg:color_white) to starship.toml..."
|
echo "Adding icon [$icon](bg:color_purple fg:color_white) to starship.toml..."
|
||||||
# Escape special characters in icon variable for sed
|
# Escape special characters in icon variable for sed
|
||||||
escaped_icon=$(printf '%s\n' "$icon" | sed -e 's/[]\/$*.^[]/\\&/g')
|
escaped_icon=$(printf '%s\n' "$icon" | sed -e 's/[]\/$*.^[]/\\&/g')
|
||||||
sed -i "5i\icon = \"$escaped_icon\"" ~/.config/starship.toml
|
sed -i "5i\icon = \"$escaped_icon\"" ~/.config/starship/starship.toml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue