diff options
| author | Peter Son Struschka <me@peter-struschka.com> | 2020-02-02 12:50:32 +0800 |
|---|---|---|
| committer | Peter Son Struschka <me@peter-struschka.com> | 2020-02-02 12:50:32 +0800 |
| commit | f2b18aab5a84d04a36f4194473680ad70bdb5578 (patch) | |
| tree | e9db24237556f25832811d224bcb7898f22d5d1a /basics/.local/bin/locate-config | |
| parent | 2bb9010d2e613206ce3d476dbea81eb9a56f3c66 (diff) | |
| download | dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.gz dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.bz2 dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.lz dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.xz dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.zst dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.zip | |
script to find and edit config files
Diffstat (limited to 'basics/.local/bin/locate-config')
| -rwxr-xr-x | basics/.local/bin/locate-config | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/basics/.local/bin/locate-config b/basics/.local/bin/locate-config new file mode 100755 index 0000000..d798a39 --- /dev/null +++ b/basics/.local/bin/locate-config @@ -0,0 +1,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 |
