Skip to content

Instantly share code, notes, and snippets.

@mibli
Last active May 23, 2017 08:06
Show Gist options
  • Save mibli/3defce819e1ea8ae4e8bd68e4d9bc28f to your computer and use it in GitHub Desktop.
Save mibli/3defce819e1ea8ae4e8bd68e4d9bc28f to your computer and use it in GitHub Desktop.
Temporary lf bookmarks implementation
cmd mark-new ${{
# querying mark
read -e -p "Mark as: " -n 1 markchar
markfile="${XDG_CONFIG_HOME:-$HOME/.config}/lf/marks"
# removing old mark if present
sed -i "/^$markchar .*/d" "$markfile"
# adding new mark
{ cat "$markfile" 2>/dev/null;
echo "$markchar" "$(pwd)"; } |
sort > "$markfile.tmp"
mv -f "${markfile}.tmp" "$markfile"
}}
cmd mark-cd ${{
# loading and presenting
markfile="${XDG_CONFIG_HOME:-$HOME/.config}/lf/marks"
echo "Current marks:"
cat "$markfile" 2>/dev/null
# querying mark
read -e -p "Go to mark: " -n 1 markchar
dir=$(grep -e "^$markchar" < "$markfile" | cut -d' ' -f2)
# setting last visited dir
sed -i "/^' .*$/d" "$markfile"
echo "' $(pwd)" >> "$markfile"
# going to wanted dir
[ -n "$dir" ] && lf -remote "send $id cd $dir"
}}
map m mark-new
map "'" mark-cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment