Last active
December 12, 2024 01:01
-
-
Save n8henrie/c8c4223ca17d04dc69f059a29e5b753e to your computer and use it in GitHub Desktop.
Make alacritty into a pop-up scratchpad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuf -o pipefail | |
log() { | |
echo "$*" > /dev/stderr | |
} | |
err() { | |
log "$*" | |
exit 1 | |
} | |
main() { | |
local extra_paths | |
# inverted order | |
extra_paths=( | |
/Applications/Alacritty.app/Contents/MacOS | |
/run/current-system/sw/bin | |
/etc/profiles/per-user/"${USER}"/bin | |
) | |
for p in "${extra_paths[@]}"; do | |
PATH=${p}:${PATH} | |
done | |
local platform | |
platform=$(uname -s) | |
local clip paste | |
case "${platform}" in | |
Darwin) | |
clip=(pbcopy) | |
paste=(pbpaste) | |
;; | |
Linux) | |
clip=(xclip -r -selection clipboard) | |
paste=(xclip -selection clipboard -out) | |
;; | |
*) | |
err "Unknown platform: ${platform}" | |
;; | |
esac | |
local -r tmp_file=$(mktemp) | |
trap 'rm -f '"${tmp_file}" EXIT | |
"${paste[@]}" > "${tmp_file}" | |
alacritty \ | |
--class="__text_scratchpad" \ | |
--command hx "${tmp_file}" && | |
# this removes the trailing newline | |
printf "%s" "$(< "${tmp_file}")" | "${clip[@]}" | |
# belt and suspenders for cleanup | |
rm -f "${tmp_file}" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment