Browse Source

initial commit

schaeferpp 1 year ago
commit
aa66867c1f
14 changed files with 387 additions and 0 deletions
  1. 41 0
      auto_monitor.sh
  2. BIN
      boilr
  3. 17 0
      colorshow.sh
  4. BIN
      find-cursor
  5. 47 0
      gtk3switch.sh
  6. 40 0
      i3-get-class.sh
  7. BIN
      launcher
  8. 12 0
      luks-open.sh
  9. 11 0
      pdfxtract.sh
  10. 13 0
      polybar-restart.sh
  11. 9 0
      random-wallpaper.sh
  12. 12 0
      scrot.sh
  13. 99 0
      shrinkpdf.sh
  14. 86 0
      switch_monitors.sh

+ 41 - 0
auto_monitor.sh

@@ -0,0 +1,41 @@
+#! /bin/sh
+#
+# monitors.sh
+# Copyright (C) 2017 Fabian Ising <fabian@murgi.de>
+#
+# Distributed under terms of the Apache v2.0 license.
+#
+
+# Get out of town if something errors
+set -e
+
+HDMI_STATUS=$(</sys/class/drm/card0/card0-HDMI-A-1/status )  
+DP_STATUS=$(</sys/class/drm/card0/card0-DP-1/status )  
+
+
+echo "Rule run" >> /tmp/udev_test
+
+if [ "connected" == "$HDMI_STATUS" ]; then  
+    xrandr >> /tmp/udev_test
+    /usr/bin/xrandr --output eDP-1 --auto --left-of HDMI-1
+    /usr/bin/notify-send --urgency=low -t 5000 "Graphics Update" "HDMI plugged in"
+    echo "HDMI connected" >> /tmp/udev_test
+    xrandr >> /tmp/udev_test
+else  
+    /usr/bin/xrandr --output HDMI-1 --off
+    /usr/bin/notify-send --urgency=low -t 5000 "Graphics Update" "External monitor disconnected"    
+    echo "HDMI disconnected" >> /tmp/udev_test
+fi
+
+if [ "connected" == "$DP_STATUS" ]; then  
+    xrandr >> /tmp/udev_test
+    /usr/bin/xrandr --output eDP-1 --auto --right-of DP-1
+    /usr/bin/notify-send --urgency=low -t 5000 "Graphics Update" "HDMI plugged in"
+    echo "DP connected" >> /tmp/udev_test
+    xrandr >> /tmp/udev_test
+else  
+    /usr/bin/xrandr --output DP-1 --off
+    /usr/bin/notify-send --urgency=low -t 5000 "Graphics Update" "External monitor disconnected"    
+    echo "DP disconnected" >> /tmp/udev_test
+    exit
+fi

BIN
boilr


+ 17 - 0
colorshow.sh

@@ -0,0 +1,17 @@
+#! /bin/sh
+#
+# colorshow.sh
+# Copyright (C) 2017 Paul Schaefer <schaefer.pp@gmail.com>
+#
+# Distributed under terms of the Apache 2.0 license.
+#
+
+for x in {0..8}; do 
+    for i in {30..37}; do 
+        for a in {40..47}; do 
+            echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "
+        done
+        echo
+    done
+done
+echo ""

BIN
find-cursor


+ 47 - 0
gtk3switch.sh

@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# script to copy gtk-3.0 to ~/.config/
+# by Mr Green & darktux
+# gtk3switch version 0.2
+
+# paths
+user_home=/home/${USER}
+theme_name=$@ # all arguments....
+theme_dir=${user_home}/.themes
+system_theme_dir=/usr/share/themes
+
+if [ $# -eq 0 ]; then
+		echo
+		echo "Gtk3 themes"
+		echo "==========="
+		find ${system_theme_dir} ${theme_dir} -type d -name 'gtk-3.0' 2>/dev/null | awk -F'/' '{print $5}'
+		echo 
+		echo "To use one of above themes:"
+		echo "gtk3switch <theme_name>"
+    exit
+fi
+
+# Check if theme exists then copy it if it does
+flag=0
+for x in $system_theme_dir $theme_dir; do
+	if [ -d ${x}/"${theme_name}"/gtk-3.0 ]; then
+  	cp -a ${x}/"${theme_name}"/gtk-3.0 ${user_home}/.config
+  	echo "Gtk3 theme ${theme_name} installed"
+  	flag=1
+	fi
+done
+
+# Theme not found
+if [ "$flag" -eq 0 ]; then
+  echo "Theme: ${theme_name} not found"
+else
+# Option to tweak theme with lxappearance (after theme instalation) 
+  read -p "Tweak theme with Lxappearance ? (Y/n) " yn 
+  case $yn in
+    [Nn]* ) exit ;;
+    * )   lxappearance ;;
+  esac
+
+fi
+ 
+exit

+ 40 - 0
i3-get-class.sh

@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# i3-get-window-criteria - Get criteria for use with i3 config commands
+
+# To use, run this script, then click on a window.
+# Output is in the format: [<name>=<value> <name>=<value> ...]
+
+# Known problem: when WM_NAME is used as fallback for the 'title="<string>"' criterion,
+# quotes in "<string>" are not escaped properly. This is a problem with the output of `xprop`,
+# reported upstream: https://bugs.freedesktop.org/show_bug.cgi?id=66807
+
+PROGNAME=`basename "$0"`
+
+# Check for xwininfo and xprop
+for cmd in xwininfo xprop; do
+    if ! which $cmd > /dev/null 2>&1; then
+        echo "$PROGNAME: $cmd: command not found" >&2
+        exit 1
+    fi
+done
+
+match_int='[0-9][0-9]*'
+match_string='".*"'
+match_qstring='"[^"\\]*(\\.[^"\\]*)*"' # NOTE: Adds 1 backreference
+
+{
+    # Run xwininfo, get window id
+    window_id=`xwininfo -int | sed -nre "s/^xwininfo: Window id: ($match_int) .*$/\1/p"`
+    echo "id=$window_id"
+
+    # Run xprop, transform its output into i3 criteria. Handle fallback to
+    # WM_NAME when _NET_WM_NAME isn't set
+    xprop -id $window_id |
+        sed -nr \
+            -e "s/^WM_CLASS\(STRING\) = ($match_qstring), ($match_qstring)$/instance=\1\nclass=\3/p" \
+            -e "s/^WM_WINDOW_ROLE\(STRING\) = ($match_qstring)$/window_role=\1/p" \
+            -e "/^WM_NAME\(STRING\) = ($match_string)$/{s//title=\1/; h}" \
+            -e "/^_NET_WM_NAME\(UTF8_STRING\) = ($match_qstring)$/{s//title=\1/; h}" \
+            -e '${g; p}'
+} | sort | tr "\n" " " | sed -r 's/^(.*) $/[\1]\n/'

BIN
launcher


+ 12 - 0
luks-open.sh

@@ -0,0 +1,12 @@
+#! /bin/sh
+#
+# luks-open.sh
+# Copyright (C) 2017 Paul Schaefer <schaefer.pp@gmail.com>
+#
+# Distributed under terms of the LGPL-3.0+ license.
+#
+
+
+cryptsetup open --type luks /home/paul/data/encrypted.raw encrypted
+mount /dev/mapper/encrypted ~/encrypted
+

+ 11 - 0
pdfxtract.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+# this function uses 3 arguments:
+#     $1 is the first page of the range to extract
+#     $2 is the last page of the range to extract
+#     $3 is the input file
+#     output file will be named "inputfile_pXX-pYY.pdf"
+gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
+   -dFirstPage=${1} \
+   -dLastPage=${2} \
+   -sOutputFile=${3%.pdf}_p${1}-p${2}.pdf \
+   ${3}

+ 13 - 0
polybar-restart.sh

@@ -0,0 +1,13 @@
+#!/usr/bin/env sh
+
+# Terminate already running bar instances
+killall -q polybar
+
+# Wait until the processes have been shut down
+while pgrep -x polybar >/dev/null; do sleep 1; done
+
+# Launch bar1 and bar2
+polybar top &
+polybar bottom &
+
+echo "Bars launched..."

+ 9 - 0
random-wallpaper.sh

@@ -0,0 +1,9 @@
+#! /bin/sh
+#
+# random-wallpaper.sh
+# Copyright (C) 2017 Paul Schaefer <schaefer.pp@gmail.com>
+#
+# Distributed under terms of the Apache 2.0 license.
+#
+
+DISPLAY=:0 sudo -u paul feh --recursive --randomize --bg-fill "$1"

+ 12 - 0
scrot.sh

@@ -0,0 +1,12 @@
+#! /bin/sh
+#
+# scrot.sh
+# Copyright (C) 2017 Paul Schaefer <schaefer.pp@gmail.com>
+#
+# Distributed under terms of the Apache 2.0 license.
+#
+
+
+# import /home/paul/Pictures/Screenshot_$(date '+%Y-%m-%d_%H:%M:%S').png
+gnome-screenshot -a -f /home/paul/Pictures/Screenshot_$(date '+%Y-%m-%d_%H:%M:%S').png
+

+ 99 - 0
shrinkpdf.sh

@@ -0,0 +1,99 @@
+#!/bin/sh
+
+# http://www.alfredklomp.com/programming/shrinkpdf
+# Licensed under the 3-clause BSD license:
+#
+# Copyright (c) 2014, Alfred Klomp
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# 1. Redistributions of source code must retain the above copyright notice,
+#    this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+#    this list of conditions and the following disclaimer in the documentation
+#    and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+shrink ()
+{
+	gs					\
+	  -q -dNOPAUSE -dBATCH -dSAFER		\
+	  -sDEVICE=pdfwrite			\
+	  -dCompatibilityLevel=1.3		\
+	  -dPDFSETTINGS=/screen			\
+	  -dEmbedAllFonts=true			\
+	  -dSubsetFonts=true			\
+	  -dAutoRotatePages=/None		\
+	  -dColorImageDownsampleType=/Bicubic	\
+	  -dColorImageResolution=$3		\
+	  -dGrayImageDownsampleType=/Bicubic	\
+	  -dGrayImageResolution=$3		\
+	  -dMonoImageDownsampleType=/Bicubic	\
+	  -dMonoImageResolution=$3		\
+	  -sOutputFile="$2"			\
+	  "$1"
+}
+
+check_smaller ()
+{
+	# If $1 and $2 are regular files, we can compare file sizes to
+	# see if we succeeded in shrinking. If not, we copy $1 over $2:
+	if [ ! -f "$1" -o ! -f "$2" ]; then
+		return 0;
+	fi
+	ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )"
+	OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )"
+	if [ "$ISIZE" -lt "$OSIZE" ]; then
+		echo "Input smaller than output, doing straight copy" >&2
+		cp "$1" "$2"
+	fi
+}
+
+usage ()
+{
+	echo "Reduces PDF filesize by lossy recompressing with Ghostscript."
+	echo "Not guaranteed to succeed, but usually works."
+	echo "  Usage: $1 infile [outfile] [resolution_in_dpi]"
+}
+
+IFILE="$1"
+
+# Need an input file:
+if [ -z "$IFILE" ]; then
+	usage "$0"
+	exit 1
+fi
+
+# Output filename defaults to "-" (stdout) unless given:
+if [ ! -z "$2" ]; then
+	OFILE="$2"
+else
+	OFILE="-"
+fi
+
+# Output resolution defaults to 72 unless given:
+if [ ! -z "$3" ]; then
+	res="$3"
+else
+	res="72"
+fi
+
+shrink "$IFILE" "$OFILE" "$res" || exit $?
+
+check_smaller "$IFILE" "$OFILE"

+ 86 - 0
switch_monitors.sh

@@ -0,0 +1,86 @@
+#! /bin/sh
+#
+# switch_monitors.sh
+# Copyright (C) 2017 Fabian Ising <fabian@murgi.de>
+#                    Paul Schaefer <schaefer.pp@gmail.com>
+#
+# Distributed under terms of the Apache v2.0 license.
+#
+
+# Get info on the monitors
+HDMI_STATUS=$(</sys/class/drm/card0/card0-HDMI-A-1/status )
+HDMI_ENABLED=$(</sys/class/drm/card0/card0-HDMI-A-1/enabled)
+
+VGA_STATUS=$(</sys/class/drm/card0-VGA-1/status )
+VGA_ENABLED=$(</sys/class/drm/card0-VGA-1/enabled )
+
+DP_STATUS=$(</sys/class/drm/card0/card0-DP-1/status )
+DP_ENABLED=$(</sys/class/drm/card0/card0-DP-1/enabled )
+
+# Check to see if our state log exists
+if [ ! -f /tmp/monitor ]; then
+    touch /tmp/monitor
+    STATE=2
+else
+    STATE=$(</tmp/monitor)
+fi
+
+function mirror() {
+    if [ "connected" == "$HDMI_STATUS" ]; then
+        if [ "connected" == "$VGA_STATUS" ]; then
+            /usr/bin/xrandr --output eDP-1 --auto \
+                --output HDMI-1 --auto --same-as eDP-1 \
+                --output VGA-1 --auto --same-as HDMI-1
+        else
+            /usr/bin/xrandr --output eDP-1 --auto \
+                --output HDMI-1 --auto --same-as eDP-1
+        fi
+    elif [ "connected" == "$VGA_STATUS" ]; then
+        /usr/bin/xrandr --output eDP-1 --auto \
+            --output VGA-1 --auto --same-as eDP-1
+    else
+        /usr/bin/xrandr --output eDP-1 --auto --output VGA-1 --off --output HDMI-1 --off
+    fi
+}
+function extend() {
+    if [ "connected" == "$HDMI_STATUS" ]; then
+        if [ "connected" == "$VGA_STATUS" ]; then
+            /usr/bin/xrandr --output eDP-1 --auto \
+                --output HDMI-1 --auto --right-of eDP-1 \
+                --output VGA-1 --auto --right-of HDMI-1
+        else
+            /usr/bin/xrandr --output eDP-1 --auto \
+                --output HDMI-1 --auto --right-of eDP-1
+        fi
+    elif [ "connected" == "$VGA_STATUS" ]; then
+        /usr/bin/xrandr --output eDP-1 --auto \
+            --output VGA-1 --auto --right-of eDP-1
+    else
+        /usr/bin/xrandr --output eDP-1 --auto --output VGA-1 --off --output HDMI-1 --off
+    fi
+}
+
+# If monitors are disconnected, stay in state 1
+if [ "disconnected" == "$HDMI_STATUS" -a "disconnected" == "$VGA_STATUS" ]; then
+    STATE=5
+fi
+TYPE="eDP-1"
+case $STATE in
+    1)
+        # Enable STATE 2, Mirroring
+        mirror
+        STATE=2
+        /usr/bin/notify-send -t 5000 --urgency=low "Graphics Update" "Mirroring"
+        ;;
+    2) # Enable STATE 1, Extending
+        # eDP-1 is on, projectors are connected but inactive
+        extend
+        STATE=1
+        /usr/bin/notify-send -t 5000 --urgency=low "Graphics Update" "Extending"
+        ;;
+    *)
+        # Unknown state, assume we're in 1
+        STATE=1
+esac
+
+echo $STATE > /tmp/monitor