diff --git a/.zshc/func.zsh b/.zshc/func.zsh index 6fcb532..1b64883 100644 --- a/.zshc/func.zsh +++ b/.zshc/func.zsh @@ -88,25 +88,41 @@ function zipline { } function spectacle-screenshot { - # takes one argument, the path to save the screenshot to - if not provided, a temp file will be used + # takes two arguments: + # 1 - whether to save a recording or a screenshot (boolean) - defaults to screenshot (false) - RECORDING DOES NOT WORK ON X11 + # 2 - the path to save the screenshot/recording to - if not provided, a temp file will be used if (( ! $+commands[spectacle] )); then echo "spectacle is not installed." return 127 fi - if [[ -f "${1}" ]]; then + if [[ -z "${1}" ]]; then + readonly save_recording=false + else + readonly save_recording=$1 + fi + + if [[ -f "${2}" ]]; then echo "File already exists. Please provide a different file path, or use the zipline function to upload the file." echo "Example: zipline \"$file\"" return 1 fi - if [[ -z "${1}" ]]; then - readonly file=$(mktemp /tmp/spectacle-screenshot.XXXXXXXX.png) + if [[ -z "${2}" ]]; then + if $save_recording; then + readonly file=$(mktemp /tmp/spectacle-recording.XXXXXXXX.mp4) + else + readonly file=$(mktemp /tmp/spectacle-screenshot.XXXXXXXX.png) + fi else - readonly file=$1 + readonly file=$2 fi - command spectacle --nonotify --background --region --copy-image --output "$file" + if $save_recording; then + command spectacle --nonotify --background --record=region --copy-image --output "$file" + else + command spectacle --nonotify --background --region --copy-image --output "$file" + fi [ ! -s "$file" ] && return 1 trap 'rm -f "$file"' EXIT