2022-07-04 21:36:33 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-03-29 16:15:06 +02:00
|
|
|
# Inputs
|
2023-07-01 14:38:31 +02:00
|
|
|
bmdirs="$XDG_CONFIG_HOME/bookmarks/directories"
|
|
|
|
bmfiles="$XDG_CONFIG_HOME/bookmarks/files"
|
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"
|
2023-03-29 16:15:06 +02:00
|
|
|
lf_files="$XDG_DATA_HOME/lf/shortcut-files"
|
|
|
|
lf_dirs="$XDG_DATA_HOME/lf/shortcut-dirs"
|
|
|
|
lf_shortcuts="$XDG_CONFIG_HOME/lf/shortcutrc"
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2024-03-12 22:41:46 +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() {
|
|
|
|
mkdir -p /tmp/shortcuts
|
|
|
|
while IFS= read -r line; do
|
|
|
|
shortcut=$(echo "$line" | cut -d' ' -f1)
|
|
|
|
path=$(echo "$line" | cut -d' ' -f2); path=$(eval "echo $path")
|
|
|
|
|
|
|
|
printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs"
|
|
|
|
printf "map g%s cd \"%s\"\n" "$shortcut" "$path" >>"/tmp/shortcuts/lf_shortcuts"
|
|
|
|
printf "map %s" "$path" >>"/tmp/shortcuts/lf_dirs"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
write_files_tmp() {
|
|
|
|
read -r contents
|
|
|
|
mkdir -p /tmp/shortcuts
|
|
|
|
|
|
|
|
shortcut=$(echo "$contents" | cut -d' ' -f1)
|
|
|
|
path=$(echo "$contents" | cut -d' ' -f2);
|
|
|
|
|
|
|
|
printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs"
|
|
|
|
printf "map %s" "$path" >>"/tmp/shortcuts/lf_files"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_tmp() {
|
|
|
|
cat /tmp/shortcuts/zsh_named_dirs >"$zsh_named_dirs"
|
|
|
|
cat /tmp/shortcuts/lf_shortcuts >"$lf_shortcuts"
|
|
|
|
cat /tmp/shortcuts/lf_dirs >"$lf_dirs"
|
|
|
|
cat /tmp/shortcuts/lf_files >"$lf_files"
|
|
|
|
}
|
|
|
|
|
|
|
|
read_file() {
|
|
|
|
in_file=$1
|
|
|
|
sed 's/#.*//;/^$/d' "$in_file" | tr -s ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
clean
|
|
|
|
|
|
|
|
read_file "$bmdirs" | write_dirs_tmp
|
|
|
|
read_file "$bmfiles" | write_files_tmp
|
|
|
|
|
|
|
|
apply_tmp
|
|
|
|
|
|
|
|
clean
|