diff --git a/bindings b/bindings new file mode 100644 index 0000000..d295f56 --- /dev/null +++ b/bindings @@ -0,0 +1,42 @@ +~/.config/fish/config.fish +-> fish/nix.fish +-> fish/config.fish + +~/.config/i3/config +-> i3/config + +~/.config/i3status/config +-> i3status/config + +~/src/.srcfile +-> srcfiles/src + +~/.gitconfig +-> gitconfig + +~/.config/zls.json +-> zls.json + +~/.config/alacritty.yml +-> alacritty.yml + +~/.config/sway/config +-> sway/config + +~/.emacs +-> emacs.el + +~/.config/gtk-3.0/settings.ini +-> gtk-3.0/settings.ini + +~/.config/mpd.conf +-> mpd.conf + +~/.config/foot/foot.ini +-> foot.ini + +~/.config/nimmm.conf +-> nimmm.conf + +~/.zshrc +-> zshrc diff --git a/manage.sh b/manage.sh new file mode 100755 index 0000000..1b31abe --- /dev/null +++ b/manage.sh @@ -0,0 +1,252 @@ +#!/usr/bin/env bash + +# TODO check for duplicate lines in bindings + +set -e + +newline=$'\n' +esc=$'\e' +csi="$esc[" +reset="${csi}0m" + +bold="${csi}1m" +dim="${csi}2m" + +default="${csi}39m" +red="${csi}31m" +green="${csi}32m" +yellow="${csi}33m" + + +##### STATUS ##### + + +status_buffer="" +status_source_active="" +status_count_total=0 +status_count_managed=0 +status_count_unmanaged=0 +status_count_nonexistent=0 + +status_target_begin() { + status_buffer="" + status_source_active="" +} + +status_target_end() { + tilde_expanded_target=${1/\~/$HOME} + + if [ ! -z $status_source_active ] ; then + status_buffer="${bold}${green}*${default} $1${reset}${status_buffer}" + ((status_count_managed=status_count_managed+1)) + else + if [ -e $tilde_expanded_target ] ; then + status_buffer="${yellow}*${default} $1${status_buffer}" + ((status_count_unmanaged=status_count_unmanaged+1)) + else + status_buffer="${dim}* $1${reset}${status_buffer}" + ((status_count_nonexistent=status_count_nonexistent+1)) + fi + fi + + echo "$status_buffer" + echo + + ((status_count_total=status_count_total+1)) +} + +status_target_source() { + tilde_expanded_target=${1/\~/$HOME} + + if [ -L $tilde_expanded_target ] ; then + if [ $(readlink $tilde_expanded_target) = "${PWD}/$2" ] ; then + status_source_active="y" + status_buffer="${status_buffer}${newline} $2" + else + status_buffer="${status_buffer}${newline} ${dim}$2${reset}" + fi + else + status_buffer="${status_buffer}${newline} ${dim}$2${reset}" + fi + +} + +status_finished() { + cat < "*) + if [ -z $target_file ] ; then + echo "Parsing error: source given without target at line $line_nr" + exit 1 + fi + + source_file=${line#"-> "} + + process_target_source $target_file $source_file + ;; + ("") + if [ ! -z $target_file ] ; then + process_target_end $target_file + fi + + target_file="" + ;; + (*) + target_file=$line + + process_target_begin $target_file + ;; + esac + + # echo $line + ((line_nr=line_nr+1)) +done < "$bindings_file" + +# process last item +if [ ! -z $target_file ] ; then + process_target_end $target_file +fi + +process_finished