Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

  1. #!/usr/bin/env sh
  2. cleanup() {
  3. rm -r "$LF_UEBERZUG_TEMPDIR" 2>/dev/null
  4. kill $ueberzugpid 2>/dev/null
  5. }
  6. export LF_UEBERZUG_TEMPDIR="$(mktemp -d -t lf-ueberzug-XXXXXX)"
  7. trap cleanup INT
  8. export LF_UEBERZUG_FIFO="$LF_UEBERZUG_TEMPDIR/fifo"
  9. mkfifo "$LF_UEBERZUG_FIFO"
  10. tail -f "$LF_UEBERZUG_FIFO" | ueberzug layer --silent &
  11. ueberzugpid=$!
  12. if [ $# -ge 2 ]; then
  13. if [[ "${@: -1}" == "." ]]; then
  14. pwd > $XDG_RUNTIME_DIR/lf-last-dir
  15. else
  16. echo "${@: -1}" > $XDG_RUNTIME_DIR/lf-last-dir
  17. fi
  18. fi
  19. last_dir="$([ ! -f $XDG_RUNTIME_DIR/lf-last-dir ] || cat $XDG_RUNTIME_DIR/lf-last-dir)"
  20. fid="$(mktemp)"
  21. prev=$(pwd)
  22. cd $last_dir
  23. lf -command '$printf $id > '"$fid"'' -last-dir-path=$XDG_RUNTIME_DIR/lf-last-dir "$@"
  24. cd $prev
  25. id="$(cat "$fid")"
  26. archivemount_dir="$XDG_RUNTIME_DIR/__lf_archivemount_$id"
  27. if [ -f "$archivemount_dir" ]; then
  28. cat "$archivemount_dir" | \
  29. while read -r line; do
  30. sudo umount "$line"
  31. rmdir "$line"
  32. done
  33. rm -f "$archivemount_dir"
  34. fi
  35. if [ -f "$tmp" ]; then
  36. dir="$(cat "$tmp")"
  37. rm -f "$tmp"
  38. if [ -d "$dir" ]; then
  39. if [ "$dir" != "$(pwd)" ]; then
  40. cd "$dir"
  41. fi
  42. fi
  43. fi
  44. cleanup