aboutsummaryrefslogtreecommitdiffstats
path: root/basics/.local/bin/locate-config
blob: d798a3993defda83f502e02a96ea7f059a5f71e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /usr/bin/env bash

set -e

CONFIG_FILES=`ls -1 ~/.local/share/config-files | cut -d "" -f 1 | sort -d`
CONFIG_ARRAY=(`find ~/.local/share/config-files/ -maxdepth 1 -mindepth 1 -print0 | sort -z | xargs -r0 echo`)

INDEX=`echo "$CONFIG_FILES" | rofi -dmenu -format "i" -no-custom -mesg "Find config file for..."`
[ -z "$INDEX" ] && exit 1
SOURCE=${CONFIG_ARRAY[$INDEX]}
#echo "$CONFIG_FILES"
#for item in ${CONFIG_ARRAY[*]}
#do
#    printf " %s\n" $item
#done
# (https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself)
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
    DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

echo $SOURCE