2022-07-04 21:36:33 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-03-29 16:15:06 +02:00
|
|
|
# Inputs
|
2024-03-18 22:42:48 +01:00
|
|
|
bmdirs="$XDG_CONFIG_HOME/directories"
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-03-29 16:15:06 +02:00
|
|
|
# Outputs
|
2024-02-22 14:45:53 +01:00
|
|
|
zsh_named_dirs="$ZDOTDIR/configs/hashes"
|
2024-04-09 18:25:23 +02:00
|
|
|
# lf_dirs="$XDG_DATA_HOME/lf/shortcuts"
|
|
|
|
lf_maps="$XDG_CONFIG_HOME/lf/shortcuts"
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2024-03-18 22:42:48 +01:00
|
|
|
# TODO: Finish this function LOL
|
2024-03-20 11:54:06 +01:00
|
|
|
# find_marker() {
|
|
|
|
# file=$1
|
|
|
|
# for marker in \
|
|
|
|
# "# @SHORTCUTS@" \
|
|
|
|
# "-- @SHORTCUTS@" \
|
|
|
|
# "// @SHORTCUTS@" \
|
|
|
|
# "/* @SHORTCUTS@ */"; do
|
|
|
|
# file=$(grep -xn "$marker" "$file")
|
|
|
|
# if [ -n "$file" ]; then
|
|
|
|
# echo "$file"
|
|
|
|
# return
|
|
|
|
# fi
|
|
|
|
# done
|
|
|
|
# }
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2024-03-12 22:41:46 +01:00
|
|
|
zsh() {
|
|
|
|
xargs printf "hash -d %s=%s\n"
|
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2024-03-12 22:41:46 +01:00
|
|
|
clean() {
|
|
|
|
rm -rf "/tmp/shortcuts"
|
|
|
|
}
|
|
|
|
|
|
|
|
write_dirs_tmp() {
|
|
|
|
while IFS= read -r line; do
|
|
|
|
shortcut=$(echo "$line" | cut -d' ' -f1)
|
2024-03-18 22:42:48 +01:00
|
|
|
path=$(echo "$line" | cut -d' ' -f2)
|
|
|
|
path=$(eval "echo $path")
|
2024-03-12 22:41:46 +01:00
|
|
|
|
|
|
|
printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs"
|
2024-04-09 18:25:23 +02:00
|
|
|
# printf "%s:%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/lf_dirs"
|
|
|
|
printf "map g%s cd %s\n" "$shortcut" "$path" >>"/tmp/shortcuts/lf_maps"
|
2024-03-12 22:41:46 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_tmp() {
|
|
|
|
cat /tmp/shortcuts/zsh_named_dirs >"$zsh_named_dirs"
|
2024-04-09 18:25:23 +02:00
|
|
|
# cat /tmp/shortcuts/lf_dirs >"$lf_dirs"
|
|
|
|
cat /tmp/shortcuts/lf_maps >"$lf_maps"
|
2024-03-12 22:41:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
read_file() {
|
|
|
|
in_file=$1
|
|
|
|
sed 's/#.*//;/^$/d' "$in_file" | tr -s ' '
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:42:48 +01:00
|
|
|
trap clean EXIT
|
2024-03-12 22:41:46 +01:00
|
|
|
|
2024-04-09 18:25:23 +02:00
|
|
|
mkdir -p /tmp/shortcuts
|
|
|
|
|
2024-03-12 22:41:46 +01:00
|
|
|
read_file "$bmdirs" | write_dirs_tmp
|
|
|
|
|
|
|
|
apply_tmp
|
|
|
|
|
|
|
|
clean
|