vis, xdg-open, vis.desktop: implement own xdg-open script for vis with find dir
parent
b13ef3a62f
commit
7ec45680c7
|
@ -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)
|
|
||||||
|
|
|
@ -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
|
|
@ -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++;
|
|
Loading…
Reference in New Issue