Add config file, use defaults instead of needing a monitor number, README changes
Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
parent
37021b9757
commit
05fa630001
|
@ -4,5 +4,9 @@
|
||||||
# Dependencies
|
# Dependencies
|
||||||
This script depends on `wf-recorder`, `wofi`, and, obviously, `bash`.
|
This script depends on `wf-recorder`, `wofi`, and, obviously, `bash`.
|
||||||
|
|
||||||
# Running
|
# Installation
|
||||||
Put this script somewhere in your $PATH, and run `wf-shadow --help`
|
## Package Manager
|
||||||
|
Currently, no distributions include `wf-shadow` as a package. See "Manual Installation".
|
||||||
|
|
||||||
|
## Manual Installation
|
||||||
|
Put this script somewhere in your $PATH. To find which directories are in your $PATH, run `sed 's/:/\n/g' <<< "$PATH"`.
|
||||||
|
|
91
wf-shadow
91
wf-shadow
|
@ -16,12 +16,26 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
RUNTIME="${XDG_RUNTIME_DIR:-/run}/wf-shadow"
|
RUNTIME="${XDG_RUNTIME_DIR:-/run}/wf-shadow"
|
||||||
|
CONFIG="${WF_SHADOW_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/wf-shadow/config.sh}"
|
||||||
|
|
||||||
|
if [ ! -d "${CONFIG%/*}" ]; then
|
||||||
|
mkdir -p "${CONFIG%/*}" 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$CONFIG" ]; then
|
||||||
|
printf '' >> "$CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
MONITOR=1
|
MONITOR=1
|
||||||
AUDIO_DEV=""
|
AUDIO_DEV=""
|
||||||
VIDEO_DEV=""
|
VIDEO_DEV=""
|
||||||
VERBOSE=""
|
VERBOSE=""
|
||||||
trap 'kill $(jobs -p) 2>/dev/null' EXIT
|
WF_SHADOW_DIR="${WF_SHADOW_DIR:-"$HOME"/Videos/wf-shadow}"
|
||||||
|
WF_SHADOW_FORMAT="${WF_SHADOW_FORMAT:-%Y%m%d_%H:%M:%S}"
|
||||||
|
|
||||||
|
. "$CONFIG"
|
||||||
|
|
||||||
|
trap 'kill $(jobs -p) 2>/dev/null' EXIT
|
||||||
trap 'exit' INT
|
trap 'exit' INT
|
||||||
set -m
|
set -m
|
||||||
|
|
||||||
|
@ -33,8 +47,8 @@ if [ ! -d /tmp/wf-shadow ]; then
|
||||||
mkdir -p /tmp/wf-shadow 2>/dev/null
|
mkdir -p /tmp/wf-shadow 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "$HOME"/Videos/wf-shadow ]; then
|
if [ ! -d "$WF_SHADOW_DIR" ]; then
|
||||||
mkdir -p "$HOME"/Videos/wf-shadow 2>/dev/null
|
mkdir -p "$WF_SHADOW_DIR" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v wf-recorder &>/dev/null; then
|
if ! command -v wf-recorder &>/dev/null; then
|
||||||
|
@ -54,32 +68,35 @@ wf-shadow: A Wayland shadow recorder using wf-recorder and wofi
|
||||||
USAGE: wf-shadow OPTION [OPTIONS...]
|
USAGE: wf-shadow OPTION [OPTIONS...]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-s MONITOR, --start MONITOR Start a wf-shadow instance with display number MONITOR
|
-s, --start [MONITOR] Start a wf-shadow instance with display number MONITOR.
|
||||||
-r MONITOR, --record MONITOR Record the last few moments of video using a wofi menu
|
-r, --record [MONITOR] Record the last few moments of video using a wofi menu.
|
||||||
-e MONITOR, --end MONITOR End wf-shadow instance with display number MONITOR
|
-e, --end [MONITOR] End wf-shadow instance with display number MONITOR.
|
||||||
-a DEVICE, --audio DEVICE Use DEVICE for audio recording. Passed to wf-recorder -a
|
-a, --audio DEVICE Use DEVICE for audio recording. Passed to wf-recorder -a.
|
||||||
-V DEVICE, --video DEVICE Use DEVICE for video encoding. Passed to wf-recorder -d
|
-V, --video DEVICE Use DEVICE for video encoding. Passed to wf-recorder -d.
|
||||||
-v, --verbose Verbose output
|
-v, --verbose Verbose output.
|
||||||
-h, --help Show this menu
|
-h, --help Show this menu.
|
||||||
|
|
||||||
VARIABLES:
|
For a more in-depth guide, see wf-shadow(1)
|
||||||
\$WF_SHADOW_SAVE The directory to save clips in
|
|
||||||
\$WF_SHADOW_FORMAT The date format to save clips in
|
|
||||||
EOF
|
EOF
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
record() {
|
record() {
|
||||||
local FILE="${WF_SHADOW_SAVE:-"$HOME"/Videos/wf-shadow/}""$(date +"${WF_SHADOW_FORMAT:-%Y%m%d_%H:%M:%S}")__$2".mp4
|
local SAVE_FILE
|
||||||
if [ $VERBOSE ]; then
|
if [ ! $WF_SHADOW_SAVE ]; then
|
||||||
if ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE" &>/dev/null; then
|
SAVE_FILE="$WF_SHADOW_DIR"/"$(date +"$WF_SHADOW_FORMAT")__$2".mp4
|
||||||
notify-send "Clip saved" "$2 second clip saved to $FILE"
|
else
|
||||||
|
SAVE_FILE="$(eval "$WF_SHADOW_SAVE")"
|
||||||
|
fi
|
||||||
|
if [ -n "$VERBOSE" ]; then
|
||||||
|
if ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$SAVE_FILE" &>/dev/null; then
|
||||||
|
notify-send "Clip saved" "$2 second clip saved to $SAVE_FILE"
|
||||||
else
|
else
|
||||||
notify-send "Error saving clip" "Start a new session with --verbose to see ffmpeg output"
|
notify-send "Error saving clip" "Start a new session with --verbose to see ffmpeg output"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE"; then
|
if ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$SAVE_FILE"; then
|
||||||
notify-send "Clip saved" "$2 second clip saved to $FILE"
|
notify-send "Clip saved" "$2 second clip saved to $SAVE_FILE"
|
||||||
else
|
else
|
||||||
notify-send "Error saving clip" "Start a new session with --verbose to see ffmpeg output"
|
notify-send "Error saving clip" "Start a new session with --verbose to see ffmpeg output"
|
||||||
fi
|
fi
|
||||||
|
@ -90,8 +107,8 @@ start() {
|
||||||
local WOFI_STRING="5 seconds\n10 seconds\n15 seconds\n30 seconds\n1 minute\n5 minutes\n10 minutes\nCancel\n"
|
local WOFI_STRING="5 seconds\n10 seconds\n15 seconds\n30 seconds\n1 minute\n5 minutes\n10 minutes\nCancel\n"
|
||||||
while true; do
|
while true; do
|
||||||
for i in /tmp/wf-shadow/tmp{00..10}.mp4; do
|
for i in /tmp/wf-shadow/tmp{00..10}.mp4; do
|
||||||
touch "$i"
|
printf '' >> "$i"
|
||||||
if [ $VERBOSE ]; then
|
if [ -n "$VERBOSE" ]; then
|
||||||
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR &
|
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR &
|
||||||
else
|
else
|
||||||
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR &>/dev/null &
|
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR &>/dev/null &
|
||||||
|
@ -99,7 +116,12 @@ start() {
|
||||||
printf "%s" "$!" > "$RUNTIME"/"$MONITOR".pid
|
printf "%s" "$!" > "$RUNTIME"/"$MONITOR".pid
|
||||||
fg || exit
|
fg || exit
|
||||||
|
|
||||||
case "$(if [ $VERBOSE ]; then printf "$WOFI_STRING" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0; else printf "$WOFI_STRING" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 &> /dev/null; fi)" in
|
case "$(if [ -n "$VERBOSE" ]; then
|
||||||
|
printf "$WOFI_STRING" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0
|
||||||
|
else
|
||||||
|
printf "$WOFI_STRING" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 &> /dev/null
|
||||||
|
fi)" in
|
||||||
|
|
||||||
'5 seconds') record "$i" 5 ;;
|
'5 seconds') record "$i" 5 ;;
|
||||||
'10 seconds') record "$i" 10 ;;
|
'10 seconds') record "$i" 10 ;;
|
||||||
'15 seconds') record "$i" 15 ;;
|
'15 seconds') record "$i" 15 ;;
|
||||||
|
@ -114,20 +136,33 @@ start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
until [ -z "$1" ]; do
|
until [ -z "$1" ]; do
|
||||||
|
re="[0-9]+"
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'-h' | '--help') print_help ;;
|
'-h' | '--help') print_help ;;
|
||||||
'-e' | '--end')
|
'-e' | '--end')
|
||||||
END=1
|
END=1
|
||||||
MONITOR="$2"
|
if [[ "$2" =~ $re ]]; then
|
||||||
shift 2 ;;
|
MONITOR="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
shift 1
|
||||||
|
fi ;;
|
||||||
'-r' | '--record')
|
'-r' | '--record')
|
||||||
RECORD=1
|
RECORD=1
|
||||||
MONITOR="$2"
|
if [[ "$2" =~ $re ]]; then
|
||||||
shift 2 ;;
|
MONITOR="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
shift 1
|
||||||
|
fi ;;
|
||||||
'-s' | '--start')
|
'-s' | '--start')
|
||||||
START=1
|
START=1
|
||||||
MONITOR="$2"
|
if [[ "$2" =~ $re ]]; then
|
||||||
shift 2 ;;
|
MONITOR="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
shift 1
|
||||||
|
fi ;;
|
||||||
'-a' | '--audio')
|
'-a' | '--audio')
|
||||||
AUDIO_DEV="$2"
|
AUDIO_DEV="$2"
|
||||||
shift 2 ;;
|
shift 2 ;;
|
||||||
|
|
56
wf-shadow.1
56
wf-shadow.1
|
@ -24,12 +24,13 @@ and wofi(1) in order to accomplish the task.\&
|
||||||
.P
|
.P
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.P
|
.P
|
||||||
\fB-s, --start\fR \fIMONITOR\fR
|
\fB-s, --start\fR [\fIMONITOR\fR]
|
||||||
.RS 4
|
.RS 4
|
||||||
Starts a wf-shadow instance on monitor number \fIMONITOR\fR.\&
|
Starts a wf-shadow instance on monitor number \fIMONITOR\fR, if no \fIMONITOR\fR
|
||||||
|
is specified, then use monitor #1.\&
|
||||||
.P
|
.P
|
||||||
.RE
|
.RE
|
||||||
\fB-r, --record\fR \fIMONITOR\fR
|
\fB-r, --record\fR [\fIMONITOR\fR]
|
||||||
.RS 4
|
.RS 4
|
||||||
Record the last few moments of video using a wofi(1) menu.\&
|
Record the last few moments of video using a wofi(1) menu.\&
|
||||||
.P
|
.P
|
||||||
|
@ -37,7 +38,7 @@ This will use the same \fIMONITOR\fR number as any running session of
|
||||||
\fBwf-shadow\fR.\&
|
\fBwf-shadow\fR.\&
|
||||||
.P
|
.P
|
||||||
.RE
|
.RE
|
||||||
\fB-e, --end\fR \fIMONITOR\fR
|
\fB-e, --end\fR [\fIMONITOR\fR]
|
||||||
.RS 4
|
.RS 4
|
||||||
End the current instance running on monitor \fIMONITOR\fR.\&
|
End the current instance running on monitor \fIMONITOR\fR.\&
|
||||||
.P
|
.P
|
||||||
|
@ -66,7 +67,7 @@ Show a simple help menu
|
||||||
.RE
|
.RE
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT
|
||||||
.P
|
.P
|
||||||
\fBWF_SHADOW_SAVE\fR
|
\fBWF_SHADOW_DIR\fR
|
||||||
.RS 4
|
.RS 4
|
||||||
The path to the directory used to save clips.\&
|
The path to the directory used to save clips.\&
|
||||||
.P
|
.P
|
||||||
|
@ -76,6 +77,49 @@ The path to the directory used to save clips.\&
|
||||||
The date(1) \fI-d\fR format used by \fBwf-shadow\fR to save clips.\&
|
The date(1) \fI-d\fR format used by \fBwf-shadow\fR to save clips.\&
|
||||||
.P
|
.P
|
||||||
.RE
|
.RE
|
||||||
|
\fBWF_SHADOW_SAVE\fR
|
||||||
|
.RS 4
|
||||||
|
The bash(1) command to run to get the save file for clips.\& The output of
|
||||||
|
the command is used as the path.\& Overrides \fBWF_SHADOW_DIR\fR and
|
||||||
|
\fBWF_SHADOW_FORMAT\fR.\&
|
||||||
|
.P
|
||||||
|
.RE
|
||||||
|
\fBWF_SHADOW_CONFIG\fR
|
||||||
|
.RS 4
|
||||||
|
The path to the configuration file used by \fBwf-shadow\fR.\&
|
||||||
|
See \fBCONFIGURATION\fR for how to configure \fBwf-shadow\fR.\&
|
||||||
|
.P
|
||||||
|
.RE
|
||||||
|
.SH CONFIGURATION
|
||||||
|
.P
|
||||||
|
The configuration file takes the form of a bash(1) script.\& This file is sourced
|
||||||
|
after default variables are set.\& Use standard bash variable definitions in order
|
||||||
|
to set either environment variables found in \fBENVIRONMENT\fR, or the following
|
||||||
|
variables.\&
|
||||||
|
.P
|
||||||
|
\fBMONITOR\fR
|
||||||
|
.RS 4
|
||||||
|
The monitor number to use to start, end, or record on.\& Default is 1.\&
|
||||||
|
.P
|
||||||
|
.RE
|
||||||
|
\fBAUDIO_DEV\fR
|
||||||
|
.RS 4
|
||||||
|
This variable is the same as what is passed to \fI-a\fR.\& See \fBOPTIONS\fR for
|
||||||
|
more information.\&
|
||||||
|
.P
|
||||||
|
.RE
|
||||||
|
\fBVIDEO_DEV\fR
|
||||||
|
.RS 4
|
||||||
|
This variable is the same as what is passed to \fI-V\fR.\& See \fBOPTIONS\fR for
|
||||||
|
more information.\&
|
||||||
|
.P
|
||||||
|
.RE
|
||||||
|
\fBVERBOSE\fR
|
||||||
|
.RS 4
|
||||||
|
This variable is non-empty if verbose output should be enabled.\& Same as
|
||||||
|
\fI-v\fR.\&
|
||||||
|
.P
|
||||||
|
.RE
|
||||||
.SH EXAMPLES
|
.SH EXAMPLES
|
||||||
.P
|
.P
|
||||||
\fBwf-shadow\fR \fI-s\fR \fI1\fR
|
\fBwf-shadow\fR \fI-s\fR \fI1\fR
|
||||||
|
@ -109,7 +153,7 @@ Other See output.\&
|
||||||
.P
|
.P
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.P
|
.P
|
||||||
wf-recorder(1) wofi(1) ffmpeg(1) pactl(1) date(1)
|
wf-recorder(1) wofi(1) ffmpeg(1) pactl(1) date(1) bash(1)
|
||||||
.P
|
.P
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Skylar "The Cobra" Widulski <thecobra@riseup.\&net>
|
Skylar "The Cobra" Widulski <thecobra@riseup.\&net>
|
||||||
|
|
|
@ -17,16 +17,17 @@ and wofi(1) in order to accomplish the task.
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
*-s, --start* _MONITOR_
|
*-s, --start* [_MONITOR_]
|
||||||
Starts a wf-shadow instance on monitor number _MONITOR_.
|
Starts a wf-shadow instance on monitor number _MONITOR_, if no _MONITOR_
|
||||||
|
is specified, then use monitor #1.
|
||||||
|
|
||||||
*-r, --record* _MONITOR_
|
*-r, --record* [_MONITOR_]
|
||||||
Record the last few moments of video using a wofi(1) menu.
|
Record the last few moments of video using a wofi(1) menu.
|
||||||
|
|
||||||
This will use the same _MONITOR_ number as any running session of
|
This will use the same _MONITOR_ number as any running session of
|
||||||
*wf-shadow*.
|
*wf-shadow*.
|
||||||
|
|
||||||
*-e, --end* _MONITOR_
|
*-e, --end* [_MONITOR_]
|
||||||
End the current instance running on monitor _MONITOR_.
|
End the current instance running on monitor _MONITOR_.
|
||||||
|
|
||||||
*-a, --audio* _DEVICE_
|
*-a, --audio* _DEVICE_
|
||||||
|
@ -45,12 +46,43 @@ and wofi(1) in order to accomplish the task.
|
||||||
|
|
||||||
# ENVIRONMENT
|
# ENVIRONMENT
|
||||||
|
|
||||||
*WF_SHADOW_SAVE*
|
*WF_SHADOW_DIR*
|
||||||
The path to the directory used to save clips.
|
The path to the directory used to save clips.
|
||||||
|
|
||||||
*WF_SHADOW_FORMAT*
|
*WF_SHADOW_FORMAT*
|
||||||
The date(1) _-d_ format used by *wf-shadow* to save clips.
|
The date(1) _-d_ format used by *wf-shadow* to save clips.
|
||||||
|
|
||||||
|
*WF_SHADOW_SAVE*
|
||||||
|
The bash(1) command to run to get the save file for clips. The output of
|
||||||
|
the command is used as the path. Overrides *WF_SHADOW_DIR* and
|
||||||
|
*WF_SHADOW_FORMAT*.
|
||||||
|
|
||||||
|
*WF_SHADOW_CONFIG*
|
||||||
|
The path to the configuration file used by *wf-shadow*.
|
||||||
|
See *CONFIGURATION* for how to configure *wf-shadow*.
|
||||||
|
|
||||||
|
# CONFIGURATION
|
||||||
|
|
||||||
|
The configuration file takes the form of a bash(1) script. This file is sourced
|
||||||
|
after default variables are set. Use standard bash variable definitions in order
|
||||||
|
to set either environment variables found in *ENVIRONMENT*, or the following
|
||||||
|
variables.
|
||||||
|
|
||||||
|
*MONITOR*
|
||||||
|
The monitor number to use to start, end, or record on. Default is 1.
|
||||||
|
|
||||||
|
*AUDIO_DEV*
|
||||||
|
This variable is the same as what is passed to _-a_. See *OPTIONS* for
|
||||||
|
more information.
|
||||||
|
|
||||||
|
*VIDEO_DEV*
|
||||||
|
This variable is the same as what is passed to _-V_. See *OPTIONS* for
|
||||||
|
more information.
|
||||||
|
|
||||||
|
*VERBOSE*
|
||||||
|
This variable is non-empty if verbose output should be enabled. Same as
|
||||||
|
_-v_.
|
||||||
|
|
||||||
# EXAMPLES
|
# EXAMPLES
|
||||||
|
|
||||||
*wf-shadow* _-s_ _1_
|
*wf-shadow* _-s_ _1_
|
||||||
|
@ -76,7 +108,7 @@ Other See output.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
wf-recorder(1) wofi(1) ffmpeg(1) pactl(1) date(1)
|
wf-recorder(1) wofi(1) ffmpeg(1) pactl(1) date(1) bash(1)
|
||||||
|
|
||||||
# AUTHOR
|
# AUTHOR
|
||||||
Skylar "The Cobra" Widulski <thecobra@riseup.net>
|
Skylar "The Cobra" Widulski <thecobra@riseup.net>
|
||||||
|
|
Loading…
Reference in New Issue