Browse Source

Revert "nougat update"

This reverts commit 6c5964b75b.
pull/2/head
Jibreil 4 years ago
parent
commit
90f219ff0c
  1. 660
      bin/nougat
  2. 12
      i3/.config/i3/config
  3. 3
      nougat/.config/nougat
  4. 5
      nougat/.config/nougat/config.sh

660
bin/nougat

@ -1,6 +1,12 @@ @@ -1,6 +1,12 @@
#!/bin/bash
saveourship(){
cat << EOF
#!/usr/bin/env bash
# Nougat version 2
# All features from nougat 1
# ~/.config/nougat
saveourship() {
cat << EOF
Nougat - screenshot wrapper created to help organize screenshots
-h - Saves our ship.
-i - Output image to stdout. This implies -s (silent).
@ -11,13 +17,18 @@ Nougat - screenshot wrapper created to help organize screenshots @@ -11,13 +17,18 @@ Nougat - screenshot wrapper created to help organize screenshots
-f - Takes a full screen screenshot (default is select area)
-m - Takes a full screen screenshot of the currently focused monitor.
\`xdotool\` is required (\`nougat\` fallsback to a regular fullscreen screenshot without it).
-c - Puts the screenshot into your clipboard
-b - Select backend to use
Supported backends are \`maim', \`scrot' (without -m), and \`imagemagick'.
nougat will detect available backends if -b
is not specified. nougat prefers maim to scrot and imagemagick.
-p - Cleans the link directory of Nougat based on the linking policy.
Particularly useful as it cleans any links that no
longer point to a screenshot (i.e. deleted screeenshot).
EOF
exit
}
temporary=false
clean=false
silent=false
@ -25,367 +36,340 @@ stdout=false @@ -25,367 +36,340 @@ stdout=false
fullscreen=false
focused_monitor=false
copytoclipboard=false
getconfigdir(){
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
echo "$CONFIG_DIR"
backend=""
backend_options=""
backends=('maim' 'scrot' 'imagemagick')
### BACKENDS
maimbackend() {
require maim
maimopts=''
[[ $fullscreen == false ]] && maimopts=-s
[[ $focused_monitor == true ]] && maimopts=--geometry=$(getcurrentmonitor)
[[ $maimopts == "--geometry=" ]] && maimopts=''
maimopts="$maimopts --hidecursor"
maim $maimopts $backend_options /tmp/nougat_temp.png
}
configfile="`getconfigdir`/nougat/config.sh"
if [[ -f "${configfile}" ]]
then
source "${configfile}"
else
# V2
if [[ -f "`getconfigdir`/nougat" ]]
then
mv "`getconfigdir`/nougat" "`getconfigdir`/nougat.old"
source "`getconfigdir`/nougat.old"
cat >> "${configfile}" << EOF
# AUTOGENERATED CONFIG - NOUGAT V3 - PORTED FROM NOUGAT V2 CONFIG
SCREENSHOT_DIRECTORY="${NOUGAT_SCREENSHOT_DIRECTORY}"
ORGANIZATION_POLICY="${NOUGAT_ORGANIZATION_POLICY}"
NOUGAT_LINKING_POLICY="${NOUGAT_LINKING_POLICY}"
EOF
# V1
elif [[ -n "${NOUGAT_SCREENSHOT_DIRECTORY}" ]]
then
cat >> "${configfile}" << EOF
# AUTOGENERATED CONFIG - NOUGAT V3 - PORTED FROM NOUGAT V1 CONFIG
SCREENSHOT_DIRECTORY="${NOUGAT_SCREENSHOT_DIRECTORY}"
EOF
else
mkdir -p "`getconfigdir`/nougat/"
cat >> "${configfile}" << EOF
# AUTOGENERATED CONFIG - NOUGAT V3
SELECTION_METHOD="default"
SCREENSHOT_DIRECTORY="\$HOME/Pictures/Screenshots"
SCREENCAST_DIRECTORY="\$HOME/Videos/Screencasts"
DEFAULT_POLICY='\${year}/\${month}/\${day}/\${hour}:\${minute}:\${second}'
EOF
fi
source "${configfile}"
fi
unset configfile
SELECTION_METHOD="${SELECTION_METHOD:-default}"
SCREENSHOT_DIRECTORY="${SCREENSHOT_DIRECTORY:-$HOME/Pictures/Screenshots}"
SCREENCAST_DIRECTORY="${SCREENCAST_DIRECTORY:-$HOME/Videos/Screencasts}"
DEFAULT_POLICY='${year}/${month}/${day}/${hour}:${minute}:${second}'
ORGANIZATION_POLICY="${ORGANIZATION_POLICY:-$DEFAULT_POLICY}"
LINKING_POLICY="${LINKING_POLICY}"
getconfiguration(){
echo "${!1}"
scrotbackend() {
require scrot
scrotopts=''
[[ $fullscreen == false ]] && scrotopts=-s
scrot $scrotopts $backend_options /tmp/nougat_temp.png
}
require(){
command -v "$1" &> /dev/null || {
echo "$1 is not installed and is required."
exit 1
imagemagickbackend() {
require import
importopts=''
[[ $fullscreen == false && $focused_monitor == false ]] && {
require slop
slop=$(slop -qof '%wx%h+%x+%y')
[[ -n $slop ]] && importopts="-crop $slop"
} || {
[[ $focused_monitor == true ]] && importopts="-crop $(getcurrentmonitor)"
[[ $importopts == "-crop " ]] && importopts=''
}
import -window root $importopts $backend_options /tmp/nougat_temp.png
}
maketemp(){
path=`mktemp`
mv ${path} ${path}.$1
echo ${path}.$1
}
getmime(){
file --mime-type --brief $1
}
getcanonicalpaths(){
read -r year month day hour minute second <<< `date +'%Y %B %d %H %M %S'`
suffix="${1}"
extension="${2}"
if [[ "${3}" == "image" ]]
then
base_path="`getconfiguration SCREENSHOT_DIRECTORY`"
elif [[ "${3}" == "video" ]]
then
base_path="`getconfiguration SCREENCAST_DIRECTORY`"
fi
org_fullpath="${base_path}/`getconfiguration ORGANIZATION_POLICY`"
org_fullpath="${org_fullpath}${suffix}.${extension}"
if [[ -n "`getconfiguration LINKING_POLICY`" ]]
then
link_fullpath="${base_path}/`getconfiguration LINKING_POLICY`"
link_fullpath="${link_fullpath}${suffix}.${extension}"
### END BACKENDS
nobackend() {
if [[ -z $backend ]]; then
return 0
else
link_fullpath=''
return 1
fi
org_fullpath="`eval echo "${org_fullpath}"`"
link_fullpath="`eval echo "${link_fullpath}"`"
echo `dirname "${org_fullpath}"` `basename "${org_fullpath}"` `dirname "${link_fullpath}"` `basename "${link_fullpath}"`
}
temporary(){
filename=`date +'%Y-%B-%d-%H:%M:%S'`
suffix="${1}"
mime=`getmime $2`
_IFS=$IFS
IFS='/'
read -r filetype extension <<< "${mime}"
IFS=$_IFS
filename="${filename}${suffix}.${extension}"
cp "${2}" "/tmp/${filename}"
echo "/tmp/${filename}"
testfor() {
command -v "$1" &> /dev/null
return "$?"
}
save(){
mime=`getmime $2`
_IFS=$IFS
IFS='/'
read -r filetype extension <<< "${mime}"
IFS=$_IFS
read -r fullpath filename linkpath linkname <<< `getcanonicalpaths "${1}" "${extension}" "${filetype}"`
mkdir -p "${fullpath}"
[[ -n "${linkpath}" ]] && mkdir -p "${linkpath}"
cp "${2}" "${fullpath}/${filename}"
[[ -n "${linkpath}" ]] && ln -s "${fullpath}/${filename}" "${linkpath}/${linkname}"
echo "${fullpath}/${filename} ${linkpath}/${linkname}"
}
copy(){
require xclip
mime=`getmime $1`
xclip -selection clipboard -t ${mime} ${1}
}
post(){
if [[ "${copytoclipboard}" == "true" ]]
then
copy ${1}
fi
output=''
if [[ "${temporary}" == "true" ]]
then
output=`temporary "" "${1}"`
else
read -r filepath linkpath <<< `save "" "${1}"`
output="${filepath}\n${linkpath}"
fi
if [[ "${silent}" == "false" ]]
then
echo -e "${output}"
else
if [[ "${stdio}" == "true" ]]
then
if [[ ! -t 1 ]]
then
cat "${1}"
else
cat >&2 <<EOF
Refusing to output file to terminal.
--output should only be used when redirecting files
EOF
fi
fi
fi
# We're done here. Let's clean up, boys.
rm ${1}
}
select_default(){
require slop
slop -of '%w %h %x %y'
}
select_dark(){
require slop
slop -c 0,0,0,0.35 -o -l -f '%w %h %x %y'
}
select_light(){
require slop
slop -c 1,1,1,0.25 -o -l -f '%w %h %x %y'
require() {
command -v "$1" &> /dev/null || {
echo "$1 is not installed and is required"
exit 1
}
}
select_root_window(){
require xrandr
xrandr="$(xrandr --nograb | grep -E 'current [0-9]+ x [0-9]+')"
sed -r "s/^.*current ([0-9]+) x ([0-9]+),.*$/\1 \2 0 0/" <<< "$xrandr"
getconfigdir() {
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
echo "$CONFIG_DIR"
}
select_focused_monitor(){
require xdotool
require xrandr
xrandr="$(xrandr --nograb | grep -E 'connected (primary )?[0-9]+x[0-9]+\+[0-9]+\+[0-9]+')"
# Print's the current screens geometry
# Modified from:
# https://superuser.com/a/1238384
getcurrentmonitor() {
# We require xdotool to get the mouse co-ordinates (used to tell which monitor we're on)
# Without xdotool we silently fallback to a regular fullscreen screenshot
testfor xdotool || return 1
testfor xrandr || return 1
xrandr="$(xrandr --nograb)"
[[ -z "$xrandr" ]] && return 1
OFFSET_RE="\+([-0-9]+)\+([-0-9]+)"
# Get the window position
eval "$(xdotool getmouselocation --shell)"
# Loop through each screen and compare the offset with the window
# coordinates.
monitor_index=0
while read -r width height xoff yoff
while read -r name width height xoff yoff
do
if [[
"${X}" -ge "${xoff}" && "${Y}" -ge "${yoff}" && "${X}" -lt "$(($xoff+$width))" && "${Y}" -lt "$(($yoff+$height))"
]]
then
echo "${width} ${height} ${xoff} ${yoff}"
return 0
if [[ "${X}" -ge "$xoff" && \
"${Y}" -ge "$yoff" && \
"${X}" -lt "$(($xoff+$width))" && \
"${Y}" -lt "$(($yoff+$height))" ]]; then
monitor=$name
break
fi
((monitor_index++))
done <<< "$(sed -r "s/^([^ ]*).*\b([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+).*$/\2 \3 \4 \5/" <<< "$xrandr" | sort -nk4,5)"
done <<< $(grep -w connected <<< "$xrandr" |
sed -r "s/^([^ ]*).*\b([-0-9]+)x([-0-9]+)$OFFSET_RE.*$/\1 \2 \3 \4 \5/" |
sort -nk4,5)
# If we found a monitor, get its geometry.
if [[ "$monitor" ]]
then
geometry="$(grep -E "^$monitor\s" <<< "$xrandr")"
geometry="${geometry/$monitor/}"
geometry="${geometry/connected/}"
geometry="${geometry/primary/}"
awk '{print $1}' <<< "$geometry"
return $?
fi
return 1
}
require ffmpeg
record_region(){
path=`maketemp mp4`
case `getconfiguration SELECTION_METHOD` in
dark)
geometry=`select_dark`
;;
light)
geometry=`select_light`
;;
*)
geometry=`select_default`
;;
esac
sleep 0.5
[[ -z "${geometry}" ]] && exit 0
read -r width height x y <<< ${geometry}
ffmpeg -f x11grab -s ${width}x${height} -i :0.0+${x},${y} -vcodec libx264 -preset veryfast -tune zerolatency -vsync 0 -y -loglevel 0 ${path}
post ${path}
getcanonicals() {
read -r year month day hour minute second <<< "$(date +'%Y %B %d %H %M %S')"
suffix=''
[[ $fullscreen == true ]] && suffix=_full
. "$(getconfigdir)/nougat"
ORG_FULLPATH="$NOUGAT_SCREENSHOT_DIRECTORY/$NOUGAT_ORGANIZATION_POLICY"
[[ -n $NOUGAT_LINKING_POLICY ]] &&
LINK_FULLPATH="$NOUGAT_SCREENSHOT_DIRECTORY/$NOUGAT_LINKING_POLICY" ||
LINK_FULLPATH=""
echo "$(dirname "$ORG_FULLPATH")" \
"$(basename "$ORG_FULLPATH")" \
"$([[ -n $LINK_FULLPATH ]] && dirname "$LINK_FULLPATH")" \
"$([[ -n $LINK_FULLPATH ]] && basename "$LINK_FULLPATH")"
}
record_fullscreen(){
path=`maketemp mp4`
geometry=`select_root_window`
read -r width height x y <<< ${geometry}
ffmpeg -f x11grab -s ${width}x${height} -i :0.0+0,0 -vcodec libx264 -preset veryfast -tune zerolatency -vsync 0 -y -loglevel 0 ${path}
post ${path}
init() {
CONFIG_DIR=$(getconfigdir)
[[ ! -f $CONFIG_DIR/nougat ]] && {
mkdir -p "$CONFIG_DIR"
if [[ -n $NOUGAT_SCREENSHOT_DIRECTORY ]]; then
# Support for V1 configurations
echo 'NOUGAT_SCREENSHOT_DIRECTORY="'"$NOUGAT_SCREENSHOT_DIRECTORY"'"' > "$CONFIG_DIR/nougat"
else
echo 'NOUGAT_SCREENSHOT_DIRECTORY="$HOME/Screenshots"' > "$CONFIG_DIR/nougat"
fi
cat >> "$CONFIG_DIR/nougat" << EOF
NOUGAT_ORGANIZATION_POLICY="\${year}/\${month}/\${day}/\${hour}:\${minute}:\${second}\${suffix}"
NOUGAT_LINKING_POLICY="All/\${year}-\${month}-\${day}.\${hour}:\${minute}:\${second}\${suffix}"
MAIM_BACKEND_OPTIONS=""
SCROT_BACKEND_OPTIONS=""
IMAGEMAGICK_BACKEND_OPTIONS=""
EOF
}
while getopts 'hstfmcpui b:S:' option; do
case $option in
h)
saveourship
exit 0
;;
b) setbackend $OPTARG;;
# Hide cursor
p) clean=true;;
s) silent=true;;
t) temp=true;;
c) copytoclipboard=true;;
f) fullscreen=true;;
m)
fullscreen=true
focused_monitor=true
;;
i)
stdout=true
silent=true
;;
esac
done
local exitcode; exitcode="$?"
nobackend &&
testfor maim && backend=maim && return "$exitcode"
nobackend &&
testfor scrot && backend=scrot && return "$exitcode"
nobackend &&
testfor import && backend=imagemagick && return "$exitcode"
}
record_focused_monitor(){
path=`maketemp mp4`
geometry=`select_focused_monitor`
read -r width height x y <<< ${geometry}
ffmpeg -f x11grab -s ${width}x${height} -i :0.0+${x},${y} -vcodec libx264 -preset veryfast -tune zerolatency -vsync 0 -y -loglevel 0 ${path}
post ${path}
setbackend() {
supported=false
for (( index=0; index<${#backends}; index++ )); do
[[ ${backends[$index]} == "$1" ]] && {
supported=true
break
}
done
[[ $supported == false ]] && {
echo "Unsupported backend $1"
exit 1
}
cmd="$1"
[[ $cmd == imagemagick ]] && cmd=import
testfor $cmd && backend="$1"
}
require import
capture_region(){
path=`maketemp png`
case `getconfiguration SELECTION_METHOD` in
dark)
geometry=`select_dark`
runbackend() {
. "$(getconfigdir)/nougat"
case $backend in
maim)
backend_options="$MAIM_BACKEND_OPTIONS"
maimbackend
;;
scrot)
backend_options="$SCROT_BACKEND_OPTIONS"
scrotbackend
;;
light)
geometry=`select_light`
imagemagick)
backend_options="$IMAGEMAGICK_BACKEND_OPTIONS"
imagemagickbackend
;;
*)
geometry=`select_default`
echo 'No supported backend found'
exit 1
;;
esac
sleep 0.5
[[ -z "${geometry}" ]] && exit 0
read -r width height x y <<< ${geometry}
geometry="${width}x${height}+${x}+${y}"
import -window root -crop ${geometry} ${path}
post ${path}
[[ ! -f /tmp/nougat_temp.png ]] && exit 1
}
capture_fullscreen(){
path=`maketemp png`
import -window root ${path}
post ${path}
stdout() {
if [[ ! -t 1 ]]; then
cat "$1"
else
cat >&2 <<EOF
Refusing to output stdout to a terminal.
Did you mean to pipe me to another script?
$1
EOF
exit 1
fi
}
capture_focused_monitor(){
path=`maketemp png`
geometry=`select_focused_monitor`
read -r width height x y <<< ${geometry}
geometry="${width}x${height}+${x}+${y}"
import -window root -crop ${geometry} ${path}
post ${path}
organize() {
read -r fullpath filename linkpath linkname <<< "$(getcanonicals)"
[[ $copytoclipboard == true ]] && {
require xclip
xclip -selection clipboard -t image/png /tmp/nougat_temp.png
}
[[ $temp == true ]] && {
[[ $silent == false ]] && echo "/tmp/$linkname.png"
mv /tmp/nougat_temp.png "/tmp/$linkname.png"
[[ $stdout == true ]] && stdout "/tmp/$linkname.png"
exit 0
}
mkdir -p "$fullpath"
[[ -n $linkpath ]] && mkdir -p "$linkpath"
mv /tmp/nougat_temp.png "$fullpath/$filename.png"
[[ -n $linkpath ]] && ln -s "$fullpath/$filename.png" "$linkpath/$linkname.png"
[[ $silent == false ]] && echo "$fullpath/$filename.png"
[[ $stdout == true ]] && stdout "$fullpath/$filename.png"
exit 0
}
longoptions="help,silent,temporary,copy,fullscreen,monitor,output,purge"
shortoptions="h,s,t,c,f,m,i,p"
# Configuration variables
longoptions="${longoptions},selection-method:"
longoptions="${longoptions},screenshot-directory:,screencast-directory"
longoptions="${longoptions},organization-policy:,linking-policy:"
# Screenshot & record
longoptions="${longoptions},screenshot,record"
getopt_opts="--options=${shortoptions} --longoptions=${longoptions}"
parsed=`getopt ${getopt_opts} --name "$0" -- "$@"`
eval set -- "${parsed}"
action=''
setaction(){
[[ ! -z "${action}" ]] && echo 'Only a single action can be done at a time.' && exit 1
action="$1"
clean() {
. "$(getconfigdir)/nougat"
linkdir=$(dirname "$NOUGAT_SCREENSHOT_DIRECTORY/$NOUGAT_LINKING_POLICY")
[[ $silent == false ]] && echo "$linkdir"
[[ ! -d $linkdir || -z $(ls -1 "$linkdir") ]] && return 0
for file in "$linkdir/"*; do
link=$(readlink -f "$file")
if [[ ! -f $link ]]; then rm "$file"; fi
done
}
while true
do
case "$1" in
-h|--help)
saveourship
;;
-s|--silent)
silent=true
shift
;;
-t|--temporary)
temporary=true
shift
;;
-c|--copy)
copytoclipboard=true
shift
;;
-f|--fullscreen)
fullscreen=true
shift
;;
-m|--monitor)
focused_monitor=true
shift
;;
-i|--output)
silent=true
stdio=true
shift
;;
-p|--purge)
# not yet implemented
shift
;;
#config variables
--selection-method)
SELECTION_METHOD=${2:-${SELECTION_METHOD}}
shift 2
;;
--screenshot-directory)
SCREENSHOT_DIRECTORY=${2:-${SCREENSHOT_DIRECTORY}}
shift 2
;;
--screencast-directory)
SCREENCAST_DIRECTORY=${2:-${SCREENCAST_DIRECTORY}}
shift 2
;;
--organization-policy)
ORGANIZATION_POLICY=${2:-${ORGANIZATION_POLICY}}
shift 2
;;
--linking-policy)
LINKING_POLICY=${2:-${LINKING_POLICY}}
shift 2
;;
# Screenshot
--screenshot)
setaction 'capture'
shift
;;
# Record
--record)
setaction 'record'
shift
;;
--)
shift
break
;;
esac
done
if [[ ! -z "${action}" ]]
then
if [[ "$fullscreen" == "true" && "$focused_monitor" == "true" ]]
then
echo "Only one selection mode can be specified at once."
exit 1
fi
if [[ "$fullscreen" == "true" ]]
then
action="${action}_fullscreen"
elif [[ "$focused_monitor" == "true" ]]
then
action="${action}_monitor"
else
action="${action}_region"
fi
$action
else
echo "No action set."
exit 1
fi
screenshot() {
runbackend
organize
}
init "$@"
[[ $clean == true ]] && {
clean
x="$?"
[[ $# -eq 1 ]] && {
[[ $1 == -p || $1 == -ps || $1 == -sp ]] && exit "$x"
}
[[ $# -eq 2 ]] && {
[[ $1 == -p || $1 == -s ]] && {
[[ $2 == -p || $2 == -s ]] && exit "$x"
}
}
}
screenshot

12
i3/.config/i3/config

@ -267,13 +267,13 @@ bindsym $mod+Home scratchpad show @@ -267,13 +267,13 @@ bindsym $mod+Home scratchpad show
## screenshot (nougat)
bindsym $mod+Ctrl+f exec nougat --screenshot -fcs && dunstify "fullscreen screenshot saved"
bindsym $mod+Shift+f exec nougat --screenshot -fcst && dunstify "fullscreen screenshot copied"
bindsym $mod+Ctrl+s exec nougat --screenshot -cs && dunstify "area/window screenshot saved"
bindsym $mod+Shift+s exec nougat --screenshot -cst && dunstify "area/window screenshot copied"
bindsym $mod+Ctrl+f exec nougat -fcs && dunstify "fullscreen screenshot saved"
bindsym $mod+Shift+f exec nougat -fcst && dunstify "fullscreen screenshot copied"
bindsym $mod+Ctrl+s exec nougat -cs && dunstify "area/window screenshot saved"
bindsym $mod+Shift+s exec nougat -cst && dunstify "area/window screenshot copied"
bindsym Print exec nougat --screenshot -fcst && dunstify "fullscreen screenshot copied"
bindsym $mod+Print exec nougat --screenshot -fcs && dunstify "fullscreen screenshot saved"
bindsym Print exec nougat -fcst && dunstify "fullscreen screenshot copied"
bindsym $mod+Print exec nougat -fcs && dunstify "fullscreen screenshot saved"
## suspend

3
nougat/.config/nougat

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
NOUGAT_SCREENSHOT_DIRECTORY="/home/jibreil/pictures/screenshots"
NOUGAT_ORGANIZATION_POLICY="${year}/${month}/${day}/${hour}:${minute}:${second}${suffix}"
NOUGAT_LINKING_POLICY="all/${year}-${month}-${day}.${hour}:${minute}:${second}${suffix}"

5
nougat/.config/nougat/config.sh

@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
# AUTOGENERATED CONFIG - NOUGAT V3
SELECTION_METHOD="default"
SCREENSHOT_DIRECTORY="$HOME/pictures/screenshots"
SCREENCAST_DIRECTORY="$HOME/videos/recordings"
DEFAULT_POLICY='${year}/${month}/${day}/${hour}:${minute}:${second}'
Loading…
Cancel
Save