Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Last active Jul 6, 2021
Embed
What would you like to do?
edited teiler to work with fzf
#!/bin/bash
# Menus
promptDelay() {
printf "%s\n" "$@" | fzf --header="Delay:"
}
mainMenu () {
isRecording && STATE_RECORDING="4. Stop recording screencast"
menu=("0: Exit teiler"
"---"
"1. Screenshot (Active Monitor)"
"2. Screenshot (All Monitors)"
"3. Screenshot (Area)"
"${STATE_RECORDING:-"4. Screencast"}"
"---"
"5. Copy Last Image to Clipboard"
"6. Upload Text from Clipboard"
"7. Upload Menu")
prompt() {
printf "%s\n" "$@" | fzf
}
promptDelay() {
printf "%s\n" "$@" | fzf --header="Delay:"
}
case "$(prompt "${menu[@]}")" in
0:*) exit ;;
1.*) delayPrompt screenshot -w $(xininfo -mon-width) -h $(xininfo -mon-height) -x $(xininfo -mon-x) -y $(xininfo -mon-y) -d ;;
2.*) delayPrompt screenshot -d ;;
3.*) delayPrompt screenshot -s -d ;;
4.*) isRecording && stopRecording && sleep 2 && askPrompt || screencastPrompt ;;
5.*) imgClip ;;
6.*) clipUpload ;;
7.*) uploadMenu ;;
*) exit
esac
}
askPrompt () {
if [[ $upload_vid == 0 ]]; then
exit
elif [[ $upload_vid == 1 ]]; then
menu=("1. Yes"
"2. No")
prompt() {
printf "%s\n" "$@" | fzf --header="Upload Video?"
}
case "$(prompt "${menu[@]}")" in
1.*) instantUpload mp4 "$scp_path_vid" "$http_vid" ;;
2.*) exit ;;
*) exit
esac
fi
}
editImage () {
$editor "${img_path}/lastimg.png"
menu=$(echo -e "1. Yes\n2. No" | fzf --header="Upload File? >")
if [[ "$menu" == "1. Yes" ]]; then
instantUpload png "$scp_path_img" "$http_img" "$s3_path_img" "$s3_http_img"
else
exit
fi
}
uploadMenu () {
if [[ "$ul" == "fb" ]]; then history="5. Show Filebin History"; fi
menu=("0: << back to Main Menu"
"---"
"1. Upload Image from History"
"2. Upload Video from History"
"---"
"3. Upload last Image"
"4. Upload last Video"
"---"
"${history}"
)
prompt() {
printf "%s\n" "$@" | fzf --header="Upload:"
}
case "$(prompt "${menu[@]}")" in
0:*) mainMenu ;;
3.*) instantUpload png "$scp_path_img" "$http_img" "$s3_path_img" "$s3_http_img" ;;
4.*) instantUpload mp4 "$scp_path_vid" "$http_vid" "$s3_path_vid" "$s3_http_vid" ;;
1.*) upLoad "$(imgListFiles png)" "$scp_path_img" "$http_img" "$s3_path_img" "$s3_http_img" ;;
2.*) upLoad "$(vidListFiles mp4)" "$scp_path_vid" "$http_vid" "$s3_path_vid" "$s3_http_vid" ;;
5.*) fb_history ;;
*) exit
esac
}
fb_history () {
menu=$(echo -e "0: << back to main menu\n---\n$(fb -H | awk -F '|' 'NR > 2 { print $1, $2, $4, $6 }')" | tac | fzf -header="Chose Entry > ")
if [[ "$menu" == "0: << back to main menu" ]]; then
mainMenu
elif [[ "$menu" == "" ]]; then
uploadMenu
else
echo -n "${filebin_host}/$(echo ${menu} | awk '{ print $1 }')" | xclip
x_clip
notify-send "teiler" "Copied Entry to Clipboard"
fi
}
delayPrompt () {
t=$(promptDelay 0 2 5 10 20 30 '<< back to Main Menu')
[[ "$t" = *[[:digit:]]* ]] || mainMenu
[[ "$t" -gt 2 ]] && {
notify "$time" "Screenshot will be taken in $t seconds"
countdown "$t" | progress 0 "$t" &
DELAY_PID=$!
}
"$@" $((t+1))
unset DELAY_PID
killCountdown
}
# main function
# actual screenshot function
screenshot () {
type maim &>/dev/null || { echo "Missing maim!"; exit 1; }
[[ -f "${img_path}/lastimg.png" ]] && rm "${img_path}/lastimg.png"
if [[ $hidecursor == "yes" ]]; then
maim --hidecursor -b "$slop_border" -c "$slop_color" "$@" "${img_path}/lastimg.png"
else
maim -b "$slop_border" -c "$slop_color" "$@" "${img_path}/lastimg.png"
fi
if [[ $? == 1 ]]; then
exit
else
notify "$time" "Screenshot saved"
archiveImage
fi
menu=$(echo -e "1. Upload Image\n2. Edit Image" | fzf --header="> ")
if [[ "$menu" == "1. Upload Image" ]]; then
instantUpload png "$scp_path_img" "$http_img" "$s3_path_img" "$s3_http_img"
elif [[ "$menu" == "2. Edit Image" ]]; then
editImage
else
exit
fi
}
# screencast related functions (screencast, isRecording, stopRecording)
screencast () {
type avconv || type ffmpeg &>/dev/null || { echo "Missing Dependencies"; exit 1; }
isRecording && {
notify "$time" 'Screencast already in progress'
echo "Already recording Screen"; exit 1;
}
ffmpeg_display=$(echo $DISPLAY)
ffmpeg_offset=$(echo $(xininfo -mon-x),$(xininfo -mon-y))
res_now="$(echo $(xininfo -mon-size | awk '{ print $1 }')x$(xininfo -mon-size | awk '{ print $2 }'))"
if [[ $res_now == $res ]]; then
echo " "
else
output=$(xininfo -name)
xrandr --output "$output" --mode "$res"
sleep 5
fi
[[ -f "${vid_path}/lastvid.mp4" ]] && rm "${vid_path}/lastvid.mp4"
$encoder -f x11grab -s $res -i $ffmpeg_display+$ffmpeg_offset $ffaudio $encopts "${vid_path}/lastvid.mp4" &
echo "$!" > "$SCREENCAST_PIDFILE"
indicator
notify "$time" "Screencast started"
}
screencastPrompt() {
menu=("0: << back to Main Menu"
"---"
"1. Fullscreen"
"2. Area")
prompt() {
printf "%s\n" "$@" | fzf --header="Screencast:"
}
case "$(prompt "${menu[@]}")" in
0:*) mainMenu ;;
1.*) screencast ;;
2.*) screencastArea ;;
*) exit
esac
}
screencastArea () {
type avconv || type ffmpeg &>/dev/null || { echo "Missing Dependencies"; exit 1; }
isRecording && {
notify "$time" 'Screencast already in progress'
echo "Already recording Screen"; exit 1;
}
ffmpeg_display=$(echo $DISPLAY)
ffmpeg_offset=$(echo $(xininfo -mon-x),$(xininfo -mon-y))
eval `slop -b "$slop_border" -c "$slop_color"`
[[ -f "${vid_path}/lastvid.mp4" ]] && rm "${vid_path}/lastvid.mp4"
$encoder -f x11grab -s "$W"x"$H" -i $ffmpeg_display+$X,$Y $ffaudio $rect_encopts "${vid_path}/lastvid.mp4" &
echo "$!" > "$SCREENCAST_PIDFILE"
indicator
notify "$time" "Screencast started"
}
screencastInputArea () {
type avconv || type ffmpeg &>/dev/null || { echo "Missing Dependencies"; exit 1; }
isRecording && {
notify "$time" 'Screencast already in progress'
echo "Already recording Screen"; exit 1;
}
rectangle2="$(echo "$1" | awk -F '+' '{ print $2, $NF }' | sed -e 's/ /,/g')"
rectangle1="$(echo "$1" | awk -F '+' '{ print $1 }')"
echo $rectangle1
echo $rectangle2
[[ -f "${vid_path}/lastvid.mp4" ]] && rm "${vid_path}/lastvid.mp4"
$encoder -f x11grab -s $(echo $rectangle1) -i $ffmpeg_display+$(echo $rectangle2) $ffaudio $rect_encopts "${vid_path}/lastvid.mp4" &
echo "$!" > "$SCREENCAST_PIDFILE"
indicator
notify "$time" "Screencast started"
}
isRecording () {
[[ -f "$SCREENCAST_PIDFILE" ]] || return 1;
}
stopRecording () {
local pid
[[ -f $SCREENCAST_PIDFILE ]] && {
pid=$(cat "$SCREENCAST_PIDFILE")
pid2=$(cat "$INDICATOR_PIDFILE")
isRecording && kill "$pid" "$pid2"
rm "$SCREENCAST_PIDFILE"
rm "$INDICATOR_PIDFILE"
}
notify "$time" "Stopped recording"
archiveVid
output=$(xininfo -name)
xrandr --output "$output" --auto
return 0
}
# copy last image to clipboard
imgClip () {
copyq write image/png - < "$img_path"/lastimg.png &
}
# archiving functions
archiveImage () {
[[ "$archive_img" = '1' ]] || return
mv "${img_path}/lastimg.png" "${img_path}/${img_filemask}.png"
ln -s "${img_path}/${img_filemask}.png" "${img_path}/lastimg.png"
}
archiveVid () {
[[ "$archive_vid" = '1' ]] || return
mv "${vid_path}/lastvid.mp4" "${vid_path}/${vid_filemask}.mp4"
ln -s "${vid_path}/${vid_filemask}.mp4" "${vid_path}/lastvid.mp4"
}
archivePaste () {
[[ "$archive_paste" = '1' ]] || return
mv "${paste_path}/lastpaste.paste" "${paste_path}/${paste_filemask}.paste"
ln -s "${paste_path}/${paste_filemask}.paste" "${paste_path}/lastpaste.paste"
}
# misc functions
# notification and indicator functions
notify () {
notify-send -u low --hint=int:transient:1 -t "$1" "Teiler" "$2"
}
indicator () {
echo "$rec_text" | dzen2 -fn "$rec_font" -fg "$rec_nf" -bg "$rec_sf" -w "$rec_w" \
-x $(( ( $(xininfo -mon-width)-120)/2 )) -xs $(echo $(( $(xininfo -active-mon) + 1 ))) -p &
echo "$!" > "$INDICATOR_PIDFILE"
}
function countdown {
for i in $(seq $[$1-1] -1 0); do
for o in {9..0}; do
echo $i.$o; sleep 0.1
done
done
}
function killCountdown {
[[ -n "$DELAY_PID" ]] && notify 'delayed screenshot aborted!'
[[ -f "/proc/$DELAY_PID/comm" && "$(</proc/$DELAY_PID/comm)" = "$progname" ]] \
&& kill $DELAY_PID
exit 0
}
function progress {
$(echo $gdbar_binary) -min $1 -max $2 -w 100 -h 8 | dzen2 -fn "$rec_font" -fg "$rec_nf" -bg "$rec_sf" -w 120 \
-x $(( ( $(xininfo -mon-width)-120)/2 )) -xs $(echo $(( $(xininfo -active-mon) + 1 ))) -p 1
}
# filelistings for the upLoad function
imgListFiles () {
menu="$(ls -t -l "$img_path"/*."$1" | awk '{ print $5, $6, $7, $8, $9 }' | column -t -s ' ' | fzf --header="Select File > ")"
basename $(echo "$menu" | awk '{ print $5 }')
}
vidListFiles () {
ls -t -l "$vid_path"/*."$1" | awk '{ print $5, $6, $7, $8, $9 }' | column -t -s ' ' | fzf --header="Select File:"
}
# horrible long upload functions
clipUpload () {
[[ -f "${paste_path}/lastpaste.paste" ]] && rm "${paste_path}/lastpaste.paste"
x_clip
(xclip -o) > "${paste_path}/lastpaste.paste"
notify "$time" "Paste saved"
if [[ $paste_ul == scp ]]; then
scp "${paste_path}/lastpaste.paste" "$scp_host":"$scp_path_paste"/"$paste_filemask".paste
notify-send -u low --hint=int:transient:1 -t "$time" "Paste Uploaded" "${http_paste}/${paste_filemask}.paste"
echo -n "${http_paste}/${paste_filemask}.paste" | xclip
elif [[ $paste_ul == fb ]]; then
fb "${paste_path}/lastpaste.paste"
notify-send -u low --hint=int:transient:1 -t "$time" "Paste Uploaded" "$(echo -n $(xclip -o))"
elif [[ $paste_ul == ix ]]; then
x_xclip
xclip -o 2>&1 | curl -F 'f:1=<-' ix.io | tr -d "\n" | xclip
notify-send -u low --hint=int:transient:1 -t "$time" "Paste Uploaded" "$(echo -n $(xclip -o))"
fi
x_clip
archivePaste
}
upLoad () {
cd "$img_path"
if [[ $1 == png ]]; then
type="Image"
elif [[ $1 == mp4 ]]; then
type="Video"
fi
if [[ "$ul" == "scp" ]]; then
scp "$1" "$scp_host":/"$2"/
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$3/$(basename "$1")"
echo -n "$3/$(basename "$1")" | xclip
elif [[ "$ul" == "fb" ]]; then
fb "$1"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) uploaded" "$(xclip -o)"
elif [[ "$ul" == "s3" ]]; then
s3cmd --no-progress put "$1" s3://"$s3_bucket"/"$4/"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$5/$(basename "$1")"
echo -n "$5/$(basename "$1")" | xclip
elif [[ "$ul" == "imgur" ]]; then
if [[ $1 == mp4 ]]; then
notify-send -u critical --hint=int:transient:1 -t "$time" "teiler" "imgur does not support Videos"
else
imgur "$1"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$(xclip -o)"
fi
fi
x_clip
}
instantUpload () {
if [[ $1 == png ]]; then
if [[ "$archive_img" == 1 ]]; then
file=$(readlink "$img_path"/lastimg.png)
else
file="$img_path/lastimg.png"
fi
type="Image"
elif [[ $1 == mp4 ]]; then
if [[ "$archive_vid" == 1 ]]; then
file=$(readlink "$vid_path"/lastvid.mp4)
else
file="${vid_path}/lastvid.mp4"
fi
type="Video"
fi
if [[ "$ul" == "scp" ]]; then
scp "$file" "$scp_host":/"$2/"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$3/$(basename "$file")"
echo -n "$3/$(basename "$file")" | xclip
elif [[ "$ul" == "s3" ]]; then
s3cmd --no-progress put "$file" s3://"$s3_bucket"/"$4/"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$5/$(basename "$file")"
echo -n "$5/$(basename "$file")" | xclip
elif [[ "$ul" == fb ]]; then
fb "$file"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$(xclip -o)"
elif [[ "$ul" == imgur ]]; then
if [[ $1 == mp4 ]]; then
notify-send -u critical --hint=int:transient:1 -t "$time" "teiler" "imgur does not support Videos"
else
imgur "$file"
notify-send -u low --hint=int:transient:1 -t "$time" "$(echo $type) Uploaded" "$(xclip -o)"
fi
fi
x_clip
}
x_clip () {
(xclip -o) | xclip -selection clipboard
}
################################################################################################################
type dmenu &>/dev/null || type fzf &>/dev/null || { echo "Missing Dependencies"; exit 1; }
source "$HOME/.config/teiler/config"
if [[ "$backend" == "fzf" ]]
then function dmenu_t () {
fzf -dmenu $(echo "$fzfopts") "$@"
}
elif [[ "$backend" == "dmenu" ]]
then function dmenu_t () {
dmenu -l 15 "$@"
}
fi
if [[ $1 == --quick ]]; then
quick
elif [[ $1 == --cast ]]; then
isRecording && stopRecording && sleep 2 && askPrompt || screencastPrompt
elif [[ $1 == --recordarea ]]; then
screencastInputArea $2
elif [[ $1 == --quickfs ]]; then
screenshot -w $(xininfo -mon-width) -h $(xininfo -mon-height) -x $(xininfo -mon-x) -y $(xininfo -mon-y) -d 0
instantUpload png "$scp_path_img" "$http_img" "$s3_path_img" "$s3_http_img"
elif [[ $1 == --fullscreen ]]; then
delayPrompt screenshot -w $width -h $height -x $xoffset -y $yoffset -d
elif [[ $1 == --area ]]; then
delayPrompt screenshot -s -d
elif [[ $1 == --upload ]]; then
uploadMenu
elif [[ $1 == --uploadlast ]]; then
instantUpload png
elif [[ $1 == --clipboard ]]; then
clipUpload
elif [[ $1 == --check ]]; then
if ! command -v dmenu > /dev/null; then
dmenu=missing
else dmenu=installed
fi
if ! command -v fzf > /dev/null; then
fzf=missing
else fzf=installed
fi
if ! command -v scp > /dev/null; then
openssh=missing
else openssh=installed
fi
if ! command -v fb > /dev/null; then
filebin=missing
else filebin=installed
fi
if ! command -v imgur > /dev/null; then
imgur=missing
else imgur=installed
fi
if ! command -v s3cmd > /dev/null; then
s3cmd=missing
else s3cmd=installed
fi
if ! command -v xclip > /dev/null; then
xclip=missing
else xclip=installed
fi
if ! command -v dzen2 > /dev/null; then
dzen2=missing
else dzen2=installed
fi
if ! command -v ffmpeg > /dev/null; then
ffmpeg=missing
else ffmpeg=installed
fi
if ! command -v avconv > /dev/null; then
avconv=missing
else avconv=installed
fi
if ! command -v maim > /dev/null; then
maim=missing
else maim=installed
fi
if ! command -v slop > /dev/null; then
slop=missing
else slop=installed
fi
if ! command -v $(echo $gdbar_binary) > /dev/null; then
gdbar=missing
else gdbar=installed
fi
if ! command -v xininfo > /dev/null; then
xininfo=missing
else xininfo=installed
fi
if ! command -v ix > /dev/null; then
ix=missing
else ix=installed
fi
echo "Checking Dependencies"
echo ""
echo "Essential Tools:"
echo "dmenu/fzf: $dmenu/$fzf"
echo "maim: $maim"
echo "slop: $slop"
echo "ffmpeg/libav: $ffmpeg/$avconv"
echo "dzen2: $dzen2"
echo "xclip: $xclip"
echo "xininfo: $xininfo"
echo "gdbar: $gdbar"
echo ""
echo "Uploaders:"
echo "openssh: $openssh"
echo "filebin: $filebin"
echo "imgur: $imgur"
echo "s3cmd: $s3cmd"
echo "ix: $ix"
elif [[ $1 == -h ]]; then
echo "teiler 2.x: screenshot tool written in bash"
echo "Copyright © 2012 - 2014 Rasmus Steinke"
echo "https://teiler.53280.de"
echo ""
echo "Options"
echo " -h this help message"
echo " --quick screenshot of window/area and upload"
echo " --quickfs fullscreen screenshot and upload"
echo " --fullscreen fullscreen screenshot"
echo " --area screenshot of area"
echo " --clipboard upload text from clipboard"
echo " --cast start/stop screencast"
echo " --recordarea screencast specific area"
echo " example: --recordarea 500x250+10+0"
echo " --upload upload existing shots/casts"
echo " --uploadlast upload last image"
echo ""
echo " --check check for dependencies"
else
mainMenu
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment