summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Vink <ivi@vinkies.net>2025-11-28 11:05:10 +0100
committerMike Vink <ivi@vinkies.net>2025-11-28 11:05:10 +0100
commit0632884742f41b0959c1d2a118c053747e812810 (patch)
tree8cdfbe090782986c4a9275d1ef696d9e50e64589
parent452bb7c21d05a5d35220ddedc5c2e311364bfe51 (diff)
macos hacks
-rwxr-xr-x.local/bin/macos.d/dmenu_ghostty38
-rwxr-xr-x.local/bin/relativepath42
2 files changed, 80 insertions, 0 deletions
diff --git a/.local/bin/macos.d/dmenu_ghostty b/.local/bin/macos.d/dmenu_ghostty
new file mode 100755
index 0000000..439104a
--- /dev/null
+++ b/.local/bin/macos.d/dmenu_ghostty
@@ -0,0 +1,38 @@
+#!/bin/sh
+dir="${TMPDIR:-/tmp}/dmenu_ghostty"
+mkdir -p "${dir}"
+[ -p "${dir}/in" ] || mkfifo "${dir}/in"
+[ -p "${dir}/out" ] || mkfifo "${dir}/out"
+
+osa='
+on runCommandInteractively(theCommand)
+ tell application "System Events"
+ keystroke return using {command down, shift down}
+ delay 0.2
+ keystroke ("fzf <'"\${TMPDIR}/dmenu_ghostty/in"' >'"\${TMPDIR}/dmenu_ghostty/out"' && '"osascript -e 'tell application \\\"System Events\\\"' -e 'keystroke return using {command down, shift down}' -e 'end tell'"'" as text)
+ keystroke return
+ end tell
+
+end runCommandInteractively
+
+on run args
+if class of args is list then -- arguments passed come in as a list
+ set quotedArgs to {}
+ repeat with arg in args
+ -- set end of quotedArgs to "'"'"'" & arg & "'"'"'"
+ set end of quotedArgs to "" & arg
+ end repeat
+
+ set AppleScript'"'"'s text item delimiters to " "
+ set joinedArgs to quotedArgs as string
+ set AppleScript'"'"'s text item delimiters to ""
+
+ runCommandInteractively(joinedArgs)
+end if
+end run
+'
+echo "$osa"
+osascript -e "$osa" -- "$@"
+
+cat >"${dir}/in"
+cat "${dir}/out"
diff --git a/.local/bin/relativepath b/.local/bin/relativepath
new file mode 100755
index 0000000..26dc855
--- /dev/null
+++ b/.local/bin/relativepath
@@ -0,0 +1,42 @@
+#!/bin/sh
+relativepath() (
+ # both $1 and $2 are absolute paths beginning with /
+ # returns relative path to $2 from $1
+ source="$1"
+ target="$2"
+
+ commonPart="$source"
+ result=""
+
+ while [ "${target#"$commonPart"}" = "${target}" ]; do
+ # no match, means that candidate common part is not correct
+ # go up one level (reduce common part)
+ commonPart="$(dirname "$commonPart")"
+ # and record that we went back, with correct / handling
+ if [ -z $result ]; then
+ result=".."
+ else
+ result="../$result"
+ fi
+ done
+
+ if [ "$commonPart" = "/" ]; then
+ # special case for root (no common path)
+ result="$result/"
+ fi
+
+ # since we now have identified the common part,
+ # compute the non-common part
+ forwardPart="${target#"$commonPart"}"
+
+ # and now stick all parts together
+ if [ -n "$result" ] && [ -n "$forwardPart" ]; then
+ result="$result$forwardPart"
+ elif [ -n "$forwardPart" ]; then
+ # extra slash removal
+ result="${forwardPart#/}"
+ fi
+
+ echo "$result"
+)
+relativepath "$@"