Skip to content

Instantly share code, notes, and snippets.

@thennothinghappened
Created November 1, 2025 02:14
Show Gist options
  • Select an option

  • Save thennothinghappened/988cd6b89f550e4983c361e47516601e to your computer and use it in GitHub Desktop.

Select an option

Save thennothinghappened/988cd6b89f550e4983c361e47516601e to your computer and use it in GitHub Desktop.
bash-i3-screenshot-tool
#! /bin/bash
#
# Wrapper script for taking a screenshot on i3 with fancy settings :)
readonly maim_cmd="maim --select --highlight --color=0,0.5,0.6,0.5"
readonly xclip_cmp="xclip -selection clipboard -t image/png"
readonly default_save_dir="$HOME/Downloads"
case "$1" in
'file')
default_filename="Screenshot at $(date '+%Y-%m-%d %H:%M:%S').png"
temp_save_path="$(mktemp "$default_filename.XXXX")"
$maim_cmd > "$temp_save_path"
if [ $? -ne 0 ]; then
exit 1
fi
save_path="$(zenity \
--file-selection \
--save \
--filename="$default_save_dir/$default_filename")"
if [ $? -ne 0 ]; then
# Fallback to saving to the clipboard if they cancelled chosing a
# file.
cat "$temp_save_path" | $xclip_cmp
rm "$temp_save_path"
exit
fi
mv "$temp_save_path" "$save_path"
;;
'clipboard' | '')
$maim_cmd | $xclip_cmp
;;
*)
echo 'Usage: screenshot [file|clipboard]'
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment