1
0
Fork 0

vis, xdg-open, vis.desktop: implement own xdg-open script for vis with find dir

main
urosm 2024-09-16 22:32:59 +02:00
parent b13ef3a62f
commit 7ec45680c7
3 changed files with 17 additions and 29 deletions

View File

@ -144,21 +144,3 @@ e.subscribe(e.WIN_STATUS, function(win)
set_title(win.file.name or '[No Name]') set_title(win.file.name or '[No Name]')
end end
end) end)
-- find root
e.subscribe(e.WIN_OPEN, function(win)
if not win.file.path then return end
local dir = win.file.path
local home = os.getenv('HOME')
if not dir:find(home) then return end
while true do
dir = dir:match('^(.+)/[^/]+$') or home
local _, find = vis:pipe(('find %s ! -path %s -prune -type d -name .git'):format(dir, dir))
if find or dir == home then
local cmd = ('cd "%s"'):format(dir)
vis:info(cmd)
vis:command(cmd)
break
end
end
end)

View File

@ -0,0 +1,17 @@
#!/bin/sh
[ -z "$1" ] && exit
FILEPATH="$(realpath "$1")"
case "$(file -i "$FILEPATH")" in
${FILEPATH}:\ text/*)
DIRPATH="$(dirname "$FILEPATH")"
while :; do
[ "$DIRPATH" = "$HOME" ] || [ -n "$(find "$DIRPATH" ! -path "$DIRPATH" -prune -type d -name .git)" ] && break
[ "$DIRPATH" = "$(dirname "$DIRPATH")" ] && DIRPATH=$HOME || DIRPATH="$(dirname "$DIRPATH")"
done
exec $TERMINAL -D "$DIRPATH" "$EDITOR" "$FILEPATH"
;;
*) exec xdg-open "$FILEPATH" ;;
esac

View File

@ -1,11 +0,0 @@
[Desktop Entry]
Name=Vis
GenericName=Text Editor
TryExec=vis
Exec=vis %F
Terminal=true
Type=Application
Keywords=Text;editor;
Categories=Utility;TextEditor;
StartupNotify=false
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;