#!/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