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 | |
shopt -s inherit_errexit | |
log() { | |
echo "$*" > /dev/stderr | |
} | |
err() { | |
log "$*" | |
exit 1 | |
} | |
main() { | |
PATH=/opt/homebrew/bin:/Applications/Alacritty.app/Contents/MacOS:${PATH} | |
local platform | |
platform=$(uname -s) | |
local clip paste ALACRITTY | |
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 tmp_file | |
tmp_file=$(mktemp) | |
"${paste[@]}" > "${tmp_file}" | |
alacritty \ | |
--class="__text_scratchpad" \ | |
-e bash -c "nvim -c startinsert \"${tmp_file}\"" && | |
printf "%s" "$(< "${tmp_file}")" | "${clip[@]}" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment