Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Last active September 2, 2022 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8henrie/c8c4223ca17d04dc69f059a29e5b753e to your computer and use it in GitHub Desktop.
Save n8henrie/c8c4223ca17d04dc69f059a29e5b753e to your computer and use it in GitHub Desktop.
Make alacritty into a pop-up scratchpad
#!/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