From f1ae7aec9fd82b10abf17a19de69982f6c2f66da Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sun, 23 Feb 2020 12:26:29 +0100 Subject: dynamic path generation --- install.sh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 21 deletions(-) (limited to 'install.sh') diff --git a/install.sh b/install.sh index 3791729..109e7c5 100755 --- a/install.sh +++ b/install.sh @@ -1,14 +1,10 @@ #!/bin/bash -# Programs: -# compton: Compositor -# xterm fo default terminal - #Configs for home dir -MODULES=(.i3 .vim .xinitrc .compton.conf .bashrc .Xresources .radare2rc .bash_profile) +CFGS=(.i3 .vim .xinitrc .compton.conf .bashrc .Xresources .radare2rc .bash_profile) #Configs for .config -CFGFOLDER=(polybar powerline nvim termite twmn) +CFGFOLDER=(polybar powerline nvim termite twmn fish) #Scripts SCRIPTS=() @@ -18,18 +14,39 @@ yes_no() { read -p "$1 (y/[n])" inp case $inp in - [yY]* ) return 1;; - * ) return 0;; + [yY]* ) return 0;; + * ) return 1;; esac } +selector() +{ + local cnt=0 + for i in "$@" + do + echo "$cnt) $i" + ((cnt=$cnt + 1)) + done + + read -p "(default=0) >" inp + if [[ "$inp" =~ ^-?[0-9]+\$ ]] && [ $inp -ge 0 -a $inp -le $# ] + then + return $inp + elif [ -z $inp ] + then + return 0 + else + return -1 + fi + +} + #1: source 2: destination link() { if [ -e $2 ] then - yes_no "$(basename $2) exists. Overwrite?" - if [ $? -eq 0 ] + if yes_no "$(basename $2) exists. Overwrite?" then return fi @@ -45,26 +62,62 @@ link() ln -s "$1" "$2" } -echo Configs to install: ${MODULES[@]} ${CFGFOLDER[@]} + +if [ $# -gt 0 ] +then + for i in "$@" + do + echo "Install $i to" + if [ -e $i ] + then + selector "~" "~/.config" "Custom location" "Abort" + case $? in + 0) + echo "~" + break;; + 1) + echo .config + break;; + 2) + echo custom + break;; + *) + echo Abort. + break;; + esac + else + echo $i does not exist. Skipping. + fi + + done + exit 0 +fi + +WORKDIR=$(dirname $0) +cd $WORKDIR +echo Working in $WORKDIR +echo Homedir is $HOME +echo Available: ${CFGS[@]} ${CFGFOLDER[@]} git submodule init git submodule update -for mod in ${MODULES[@]}; do - yes_no "Install $mod?" - #ln -s --backup $(pwd)/$mod/ ~/$mod/ - if [ $? -eq 1 ] +for mod in "${CFGS[@]}"; do + if yes_no "Install $mod?" then - link "$(pwd)/$(dirname $0)/$mod" "$HOME/$mod" + link "$(pwd)/$mod" "$HOME/$mod" fi done -for mod in ${CFGFOLDER[@]}; do - #ln -s --backup $(pwd)/$mod/ ~/.config/$mod/ - yes_no "Install $mod?" - if [ $? -eq 1 ] +for mod in "${CFGFOLDER[@]}"; do + if yes_no "Install $mod?" then - link "$(pwd)/$(dirname $0)/$mod" "$HOME/.config/$mod" + link "$(pwd)/$mod" "$HOME/.config/$mod" fi done +#.files is used to tell scripts where to look for the dotfiles +if yes_no "Generate '.files'?"; then + echo "DOTFILEBASE=\"$(pwd)\"" > $HOME/.files +fi + -- cgit v1.2.3