├── README.md ├── banginator.sh ├── brightness.sh ├── domo.sh ├── github_get_clone_repos.sh ├── i3_empty_workspace.sh ├── i3_rename.py ├── i3_switch_workspace.sh ├── search_engine.sh ├── simpleswitcher-file-browser.sh ├── smount.sh ├── wallgig.func ├── wallgig_set_collection_wallpaper.sh ├── wallgig_set_random_wallpaper.sh └── weathernl.sh /README.md: -------------------------------------------------------------------------------- 1 | RandomScripts 2 | ============= 3 | 4 | Random Scripts I Use 5 | -------------------------------------------------------------------------------- /banginator.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | declare -A TITLES 4 | declare -A COMMANDS 5 | 6 | ### 7 | # List of defined 'bangs' 8 | ### 9 | 10 | COMMANDS['!tb']="thunderbird -compose \"to=\${input}\"" 11 | TITLES['!tb']="e-mail" 12 | 13 | COMMANDS["!ff"]="firefox \"\${input}\"" 14 | TITLES["!ff"]="Web browser" 15 | 16 | COMMANDS["!g"]="firefox --search \"\${input}\"" 17 | TITLES["!g"]="Web search" 18 | 19 | COMMANDS["!gi"]="firefox --search \"!gi \${input}\"" 20 | TITLES["!gi"]="Image search" 21 | ### 22 | # do not edit below 23 | ### 24 | 25 | ## 26 | # Generate menu 27 | ## 28 | function print_menu() 29 | { 30 | for key in ${!TITLES[@]} 31 | do 32 | echo "$key ${TITLES[$key]}" 33 | done 34 | } 35 | ## 36 | # Show rofi. 37 | ## 38 | function start() 39 | { 40 | print_menu | rofi -dmenu -p "Bang:" 41 | } 42 | 43 | 44 | # Run it 45 | value="$(start)" 46 | 47 | # Split input. 48 | # grab upto first space. 49 | choice=${value%%\ *} 50 | # graph remainder, minus space. 51 | input=${value:$((${#choice}+1))} 52 | 53 | ## 54 | # Cancelled? bail out 55 | ## 56 | if test -z ${choice} 57 | then 58 | exit 59 | fi 60 | 61 | # check if choice exists 62 | if test ${COMMANDS[$choice]+isset} 63 | then 64 | # Execute the choice 65 | eval echo "Executing: ${COMMANDS[$choice]}" 66 | eval ${COMMANDS[$choice]} 67 | else 68 | echo "Unknown command: ${choice}" | rofi -dmenu -p "error" 69 | fi 70 | -------------------------------------------------------------------------------- /brightness.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BPATH="/sys/devices/platform/s3c24xx-pwm.0/pwm-backlight.0/backlight/pwm-backlight.0" 4 | 5 | MINB=0 6 | MAXB=$(cat ${BPATH}/max_brightness) 7 | 8 | CUR=$(cat ${BPATH}/brightness) 9 | 10 | C_STATE=$(((${CUR}*100)/${MAXB})) 11 | 12 | function list_brightness() 13 | { 14 | for val in 5 10 15 30 50 70 100 15 | do 16 | if [ ${val} -eq ${C_STATE} ] 17 | then 18 | echo "*${val} %" 19 | else 20 | echo "${val} %" 21 | fi 22 | done 23 | } 24 | 25 | VAL=$(list_brightness | rofi -dmenu -p "brightness:") 26 | 27 | if [ -n "${VAL}" ] 28 | then 29 | NEW_STATE=$((${VAL% *}*${MAXB}/100)) 30 | echo ${NEW_STATE} > ${BPATH}/brightness 31 | fi 32 | 33 | 34 | -------------------------------------------------------------------------------- /domo.sh: -------------------------------------------------------------------------------- 1 | # ! /usr/bin/env bash 2 | 3 | LIGHT_HOST=192.150.0.112 4 | LIGHT_PORT=8888 5 | 6 | prompt() { 7 | printf "%s\n" "$@" | rofi -dmenu -p "Domotica:" 8 | } 9 | 10 | function get_range_value() 11 | { 12 | menu=( 13 | "0. Lights 0%" 14 | "10. Lights 10%" 15 | "20. Lights 20%" 16 | "30. Lights 30%" 17 | "40. Lights 40%" 18 | "50. Lights 50%" 19 | "60. Lights 60%" 20 | "70. Lights 70%" 21 | "80. Lights 80%" 22 | "90. Lights 90%" 23 | "100. Lights 100%" 24 | ) 25 | prompt "${menu[@]}" 26 | } 27 | 28 | function set_lights() 29 | { 30 | case "$(get_range_value)" in 31 | 0.*) echo "0" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 32 | notify-send "Domotica" "Set light level: off." 33 | ;; 34 | 10.*) echo "2" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 35 | notify-send "Domotica" "Set light level: 10%." 36 | ;; 37 | 20.*) echo "4" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 38 | notify-send "Domotica" "Set light level: 20%." 39 | ;; 40 | 30.*) echo "8" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 41 | notify-send "Domotica" "Set light level: 30%." 42 | ;; 43 | 40.*) echo "16" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 44 | notify-send "Domotica" "Set light level: 40%." 45 | ;; 46 | 50.*) echo "32" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 47 | notify-send "Domotica" "Set light level: 50%." 48 | ;; 49 | 60.*) echo "64" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 50 | notify-send "Domotica" "Set light level: 60%." 51 | ;; 52 | 70.*) echo "128" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 53 | notify-send "Domotica" "Set light level: 70%." 54 | ;; 55 | 80.*) echo "256" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 56 | notify-send "Domotica" "Set light level: 90%." 57 | ;; 58 | 90.*) echo "512" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 59 | notify-send "Domotica" "Set light level: 90%." 60 | ;; 61 | 100.*) echo "1024" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 62 | notify-send "Domotica" "Set light level: 100%." 63 | ;; 64 | esac 65 | } 66 | function set_maximum() 67 | { 68 | case "$(get_range_value)" in 69 | 0.*) echo "setmax 0" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 70 | 10.*) echo "setmax 2" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 71 | 20.*) echo "setmax 4" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 72 | 30.*) echo "setmax 8" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 73 | 40.*) echo "setmax 16" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 74 | 50.*) echo "setmax 32" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 75 | 60.*) echo "setmax 64" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 76 | 70.*) echo "setmax 128" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 77 | 80.*) echo "setmax 256" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 78 | 90.*) echo "setmax 512" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 79 | 100.*) echo "setmax 1024" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 80 | esac 81 | } 82 | function set_minimum() 83 | { 84 | case "$(get_range_value)" in 85 | 0.*) echo "setmin 0" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 86 | 10.*) echo "setmin 2" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 87 | 20.*) echo "setmin 4" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 88 | 30.*) echo "setmin 8" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 89 | 40.*) echo "setmin 16" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 90 | 50.*) echo "setmin 32" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 91 | 60.*) echo "setmin 64" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 92 | 70.*) echo "setmin 128" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 93 | 80.*) echo "setmin 256" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 94 | 90.*) echo "setmin 512" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 95 | 100.*) echo "setmin 1024" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT};; 96 | esac 97 | } 98 | 99 | 100 | function get_maximum() 101 | { 102 | sleep 0.05 103 | echo "getmax" | nc 192.150.0.109 8888 104 | } 105 | 106 | function get_minimum() 107 | { 108 | sleep 0.05 109 | echo "getmin" | nc 192.150.0.109 8888 110 | } 111 | function configure() 112 | { 113 | menu=( 114 | "Auto lights mode setup" 115 | "1. Set minimum value." 116 | "2. Set maximum value." 117 | "" 118 | "Current minimum: $(get_minimum)" 119 | "Current maximum: $(get_maximum)" 120 | ) 121 | 122 | 123 | case "$(prompt "${menu[@]}")" in 124 | 1.*) set_minimum;; 125 | 2.*) set_maximum;; 126 | esac 127 | } 128 | 129 | function menu() 130 | { 131 | menu=( 132 | "Lights on/off" 133 | "" 134 | "10. Lights Low" 135 | "60. Lights Middle" 136 | "100. Lights Full" 137 | "%. Lights (advanced)" 138 | "" 139 | "Configure" 140 | ) 141 | 142 | case "$(prompt "${menu[@]}")" in 143 | "Lights on/off") echo "toggle" "switch" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 144 | notify-send "Domotica" "Toggle light." 145 | ;; 146 | 10.*) echo "2" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 147 | notify-send "Domotica" "Set light level: 10%." 148 | ;; 149 | 20.*) echo "4" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 150 | notify-send "Domotica" "Set light level: 20%." 151 | ;; 152 | 30.*) echo "8" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 153 | notify-send "Domotica" "Set light level: 30%." 154 | ;; 155 | 40.*) echo "16" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 156 | notify-send "Domotica" "Set light level: 40%." 157 | ;; 158 | 50.*) echo "32" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 159 | notify-send "Domotica" "Set light level: 50%." 160 | ;; 161 | 60.*) echo "64" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 162 | notify-send "Domotica" "Set light level: 60%." 163 | ;; 164 | 70.*) echo "128" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 165 | notify-send "Domotica" "Set light level: 70%." 166 | ;; 167 | 80.*) echo "256" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 168 | notify-send "Domotica" "Set light level: 80%." 169 | ;; 170 | 90.*) echo "512" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 171 | notify-send "Domotica" "Set light level: 90%." 172 | ;; 173 | 100.*) echo "1024" | nc -q0 ${LIGHT_HOST} ${LIGHT_PORT}; 174 | notify-send "Domotica" "Set light level: 100%." 175 | ;; 176 | \%.*) set_lights;; 177 | Configure) 178 | configure 179 | ;; 180 | esac 181 | } 182 | 183 | menu 184 | -------------------------------------------------------------------------------- /github_get_clone_repos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | USER=DaveDavenport 4 | HOST=github 5 | 6 | 7 | REPOS=$( 8 | curl https://api.github.com/users/${USER}/repos | 9 | grep "full_name" | 10 | sed 's/[ \t]*\"\(.*\)\": \"\(.*\)",/\2/g' 11 | ) 12 | 13 | 14 | for REPO in ${REPOS} 15 | do 16 | echo "=== Updating repo: ${REPO}" 17 | REPO_DIR=$(basename ${REPO}) 18 | 19 | if [ -d ${REPO_DIR} ] 20 | then 21 | pushd ${REPO_DIR} 22 | git pull 23 | popd 24 | else 25 | git clone ${HOST}:${REPO} 26 | fi 27 | 28 | done 29 | -------------------------------------------------------------------------------- /i3_empty_workspace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MAX_DESKTOPS=20 4 | 5 | WORKSPACES=$(seq -s '\n' 1 1 ${MAX_DESKTOPS}) 6 | 7 | EMPTY_WORKSPACE=$( (i3-msg -t get_workspaces | tr ',' '\n' | grep num | awk -F: '{print int($2)}' ; \ 8 | echo -e ${WORKSPACES} ) | sort -n | uniq -u | head -n 1) 9 | 10 | i3-msg workspace ${EMPTY_WORKSPACE} 11 | -------------------------------------------------------------------------------- /i3_rename.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Needs: https://github.com/ziberna/i3-py 3 | 4 | import i3 5 | import subprocess 6 | 7 | def i3rnwps(): 8 | rnwps = {} 9 | wps = i3.get_workspaces() 10 | for wp in wps: 11 | workspace = i3.filter(num=wp['num']) 12 | if not workspace: 13 | continue 14 | workspace = workspace[0] 15 | windows = i3.filter(workspace, nodes=[]) 16 | instances = {} 17 | # Adds windows and their ids to the rnwps dictionary 18 | if len(windows) == 1: 19 | win =windows[0] 20 | if win.has_key('window_properties'): 21 | rnwps[workspace['name']] = "%i: %s" % (workspace['num'], win['window_properties']['class']) 22 | elif len(windows) == 0: 23 | rnwps[workspace['name']] = "%i: Empty" % (workspace['num']) 24 | else: 25 | names={} 26 | for win in windows: 27 | if win.has_key('window_properties'): 28 | if not names.has_key(win['window_properties']['class']): 29 | names[win['window_properties']['class']]=1 30 | else: 31 | names[win['window_properties']['class']]=names[win['window_properties']['class']]+1 32 | str="%i: " %(workspace['num']) 33 | for name in names.keys(): 34 | str+="%ix%s " %(names[name], name) 35 | rnwps[workspace['name']] = str 36 | return rnwps 37 | 38 | def rename(): 39 | rnwps = i3rnwps() 40 | print rnwps 41 | for desk in rnwps.keys(): 42 | print(desk) 43 | if desk != rnwps[desk]: 44 | i3.rename('workspace', "\"%s\"" % (desk),'to', rnwps[desk]) 45 | 46 | def watch(a,b,c): 47 | print(a) 48 | rename() 49 | 50 | if __name__ == '__main__': 51 | #subscription = i3.Subscription(watch, 'workspace') 52 | rename() 53 | 54 | -------------------------------------------------------------------------------- /i3_switch_workspace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function gen_workspaces() 4 | { 5 | i3-msg -t get_workspaces | tr ',' '\n' | grep "name" | sed 's/"name":"\(.*\)"/\1/g' | sort -n 6 | } 7 | 8 | 9 | WORKSPACE=$( (echo empty; gen_workspaces) | rofi -dmenu -p "Select workspace:") 10 | 11 | if [ x"empty" = x"${WORKSPACE}" ] 12 | then 13 | i3_empty_workspace.sh 14 | elif [ -n "${WORKSPACE}" ] 15 | then 16 | i3-msg workspace "${WORKSPACE}" 17 | fi 18 | -------------------------------------------------------------------------------- /search_engine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | QUERY=$(echo -n | simpleswitcher -dmenu -p "Search:" -loc 0 -o 80 -font "Source Code Pro-10" -padding 3 -bg "#333" -fg "#1aa" -hlfg "#111" -hlbg "#1aa" -bc "#277" ) 4 | 5 | if [ -n "${QUERY}" ] 6 | then 7 | firefox -search "$QUERY" 8 | fi 9 | -------------------------------------------------------------------------------- /simpleswitcher-file-browser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | EDITOR=xdg-open 4 | 5 | 6 | function list_directory() 7 | { 8 | echo ".." 9 | ls 10 | } 11 | 12 | declare -i quit=0; 13 | while [ $quit != 1 ]; 14 | do 15 | SELECTED=$(list_directory | simpleswitcher -dmenu -p ${PWD} ) 16 | 17 | # Check if directory 18 | if [ -d "${SELECTED}" ] 19 | then 20 | pushd "${SELECTED}" 21 | elif [ x"${SELECTED}" = x".." ] 22 | then 23 | popd 24 | elif [ -x "${SELECTED}" ] 25 | then 26 | ./"${SELECTED}" 27 | quit=1; 28 | elif [ -f "${SELECTED}" ] 29 | then 30 | ${EDITOR} "${SELECTED}" 31 | quit=1; 32 | elif [ -z "${SELECTED}" ] || [ x"${SELECTED}" = x"quit" ] 33 | then 34 | quit=1; 35 | fi 36 | done 37 | -------------------------------------------------------------------------------- /smount.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script is written by Qball Cow 3 | # This script is public domain, you are free todo whatever you like with it. 4 | # 5 | # Config file ~/.smount.conf 6 | # stucture: 7 | # =: 8 | # =: 9 | # 10 | # Autocomplete function: 11 | # 12 | #_smount.sh() 13 | #{ 14 | # COMPREPLY=() 15 | # curw=${COMP_WORDS[COMP_CWORD]} 16 | # COMPREPLY=($(compgen -W '$(smount.sh -l)' -- $curw)) 17 | #} 18 | #complete -F _smount.sh smount.sh 19 | # 20 | 21 | BASH=bash 22 | CONF_FILE=~/.smount.conf 23 | DIRECTORY=~/.remote/ 24 | 25 | 26 | function clearlock() 27 | { 28 | NAME="${1}" 29 | RPATH="${DIRECTORY}/${NAME}" 30 | if [ -f "${RPATH}.count" ]; 31 | then 32 | rm "${RPATH}.count"; 33 | fi 34 | } 35 | 36 | # create a numbered lock. 37 | # return 0 when lock is newly created. 38 | # returns 1 when lock existed (it increments the lock count) 39 | function lock() 40 | { 41 | NAME="${1}" 42 | RPATH="${DIRECTORY}/${NAME}" 43 | lockfile-create "${RPATH}" 44 | if [ -f "${RPATH}.count" ]; 45 | then 46 | echo $(($(cat "${RPATH}.count")+1)) > "${RPATH}.count" 47 | lockfile-remove "${RPATH}" 48 | return 1 49 | else 50 | echo 1 > "${RPATH}.count" 51 | lockfile-remove "${RPATH}" 52 | return 0 53 | fi 54 | } 55 | 56 | # unlock a numbered lock. 57 | # returns 0 if last lock is gone. 58 | # returns 1 if something still holds a lock. 59 | function unlock() 60 | { 61 | NAME="${1}" 62 | RPATH="${DIRECTORY}/${NAME}" 63 | 64 | lockfile-create "${RPATH}" 65 | if [ -f "${RPATH}.count" ]; 66 | then 67 | echo $(($(cat "${RPATH}.count")-1)) > "${RPATH}.count" 68 | if [ $(cat "${RPATH}.count") = 0 ] 69 | then 70 | # remove count file. 71 | rm "${RPATH}.count" 72 | # remove lock 73 | lockfile-remove "${RPATH}" 74 | return 0 75 | else 76 | # remove lock 77 | lockfile-remove "${RPATH}" 78 | return 1 79 | fi 80 | else 81 | # No count file? then assume no lock. 82 | lockfile-remove "${RPATH}" 83 | return 0 84 | fi 85 | } 86 | 87 | 88 | ## 89 | # mount it, and go in. 90 | ## 91 | function smount() 92 | { 93 | # SSH mount name. 94 | NAME="${1}" 95 | 96 | 97 | eval SSH_mount=\$${1} 98 | if [ -z "${SSH_mount}" ] 99 | then 100 | echo "Profile \"${NAME}\" does not exists"; 101 | exit 0; 102 | fi 103 | 104 | # Remote path 105 | RPATH="${DIRECTORY}/${NAME}" 106 | 107 | if [ ! -d "${RPATH}" ] 108 | then 109 | mkdir "${RPATH}"; 110 | fi 111 | 112 | # Mount 113 | if lock "${NAME}" 114 | then 115 | echo "Mounting: ${NAME}" 116 | sshfs "${SSH_mount}" "${RPATH}" 117 | 118 | # Check if mount worked. 119 | if [ "$?" != "0" ] 120 | then 121 | echo "Failed to mount: ${SSH_mount}"; 122 | # Undo set lock 123 | unlock "${NAME}" 124 | exit 0; 125 | fi 126 | else 127 | if $(mount | awk -v val="${SSH_mount}" '($1 == val) {exit 1}') 128 | then 129 | echo "Failed to lock, stall lock file" 130 | clearlock "${NAME}" 131 | smount "${NAME}" 132 | exit 0; 133 | fi 134 | fi 135 | 136 | # set profile 137 | export SP_PROFILE="SSH:${NAME}" 138 | pushd "${RPATH}" 2&>/dev/null 139 | 140 | # Enter interactive subshell 141 | ${BASH} 142 | popd 2&>/dev/null 143 | 144 | # Unmount it again. 145 | if unlock "${NAME}" 146 | then 147 | echo "Unmounting" 148 | fusermount -uz "${RPATH}" 149 | fi 150 | } 151 | 152 | 153 | list_profiles() 154 | { 155 | # should be able todo this in one command. 156 | egrep -E "^(.*)=.*$" ${CONF_FILE} | awk -F'=' '{print $1}' 157 | } 158 | 159 | function check() 160 | { 161 | if [ -z "$1" ]; then 162 | echo "Usage: smount.sh "; 163 | exit 0; 164 | fi 165 | 166 | if [ ! -d "${DIRECTORY}" ]; then 167 | mkdir "${DIRECTORY}"; 168 | fi 169 | 170 | if [ ! -z "${SP_PROFILE}" ] 171 | then 172 | echo "Already inside a mount/profile"; 173 | exit; 174 | fi 175 | 176 | } 177 | ## 178 | # option parser 179 | ## 180 | while getopts hlvrd:s: OPT; do 181 | case "$OPT" in 182 | l) 183 | list_profiles 184 | exit 0 185 | ;; 186 | esac 187 | done 188 | # Remove the switches we parsed above. 189 | shift `expr $OPTIND - 1` 190 | 191 | 192 | 193 | check $@ 194 | source "${CONF_FILE}" 195 | smount $@ 196 | -------------------------------------------------------------------------------- /wallgig.func: -------------------------------------------------------------------------------- 1 | ## 2 | # Written by: qball _at_ gmpclient _dot_ org 3 | # 4 | # Script fetches a random wallpaper from wallgig.net collection and sets this as background. 5 | # 6 | # This script is public domain, you are free todo whatever you like with it. 7 | # The tools by this script are not! 8 | # 9 | # Script uses the following external tools, drop in replacements can be inserted: 10 | # Curl: To fetch data from the interwebs 11 | # Install: See package manager. 12 | # MultiMonitorBackground: Set background wallpaper (multi monitor aware) 13 | # Install: https://github.com/DaveDavenport/MultiMonitorBackground 14 | ## 15 | 16 | 17 | ## 18 | # @argument a wallgig image ID. 19 | # 20 | # Sets background image from Cache 21 | ## 22 | function cache_set_wallpaper() 23 | { 24 | if [ -n "${CACHE_DIR}" ] 25 | then 26 | IMAGE_PATH="${CACHE_DIR}/$1.jpg" 27 | ${BG_SET_CMD} "${IMAGE_PATH}" 28 | fi 29 | } 30 | 31 | ## 32 | # sorts, counts and gets the least viewed 33 | # cache image. 34 | # 35 | # @returns wallgig image id of least viewed image. 36 | ## 37 | function get_least_viewed_cache_image() 38 | { 39 | IMAGE_ID=$(cat "${PREVIOUS_IDS_LIST}" | sort -n | uniq -c | sort -n | head -n1 | awk '{print $2}') 40 | echo "${IMAGE_ID}" 41 | } 42 | 43 | function get_random_cache_image() 44 | { 45 | IMAGE_ID=$(ls "${CACHE_DIR}" | sort -R | head -n1) 46 | echo "${IMAGE_ID%%.*}" 47 | } 48 | 49 | ## 50 | # @argument wallgig image id. 51 | # 52 | # Get the download url for image with id. 53 | ## 54 | function fetch_image() 55 | { 56 | URL="http://wallgig.net/wallpapers/$1/" 57 | WP_PATH=$(${CURL} "$URL" 2>/dev/null | grep \/dev/null 60 | } 61 | 62 | ## 63 | # Download list of wallpaper ids from url: $1 64 | ## 65 | function download_ids () 66 | { 67 | local curl="$1" 68 | ${CURL} "$curl" 2>/dev/null | grep "data-wallpaper-id" | sed "s|.*data-wallpaper-id='\(.*\)'.*|\1|g" 69 | } 70 | 71 | 72 | ## 73 | # Set image 74 | ## 75 | function set_image () 76 | { 77 | local IMAGE_ID="$1" 78 | 79 | echo "Selected image: ${IMAGE_ID}" 80 | # Store image 81 | echo ${IMAGE_ID} >> ${PREVIOUS_IDS_LIST} 82 | ## 83 | # If cache is set, lookup image in cache, otherwise fetch it. 84 | ## 85 | if [ -n "${CACHE_DIR}" ] 86 | then 87 | CACHE_FILE="${CACHE_DIR}/${IMAGE_ID}.jpg" 88 | 89 | if [ -f ${CACHE_FILE} ] 90 | then 91 | echo Get image from cache: ${CACHE_FILE} 92 | cache_set_wallpaper "${IMAGE_ID}" 93 | else 94 | # Get wallpaper url from the image page 95 | echo Fetching location for image id: ${IMAGE_ID} 96 | fetch_image "${IMAGE_ID}" "${CACHE_FILE}" 97 | cache_set_wallpaper "${IMAGE_ID}" 98 | fi 99 | else 100 | # Get wallpaper url from the image page 101 | echo Fetching location for image id: ${IMAGE_ID} 102 | fetch_image "${IMAGE_ID}" "/tmp/wallpaper.jpg" 103 | ${BG_SET_CMD} /tmp/wallpaper.jpg 104 | fi 105 | 106 | } 107 | -------------------------------------------------------------------------------- /wallgig_set_collection_wallpaper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## 4 | # wallgig_set_collection_wallpaper.sh 5 | # Written by: qball _at_ gmpclient _dot_ org 6 | # 7 | # Script fetches a random wallpaper from wallgig.net collection and sets this as background. 8 | # 9 | # This script is public domain, you are free todo whatever you like with it. 10 | # The tools by this script are not! 11 | # 12 | # Script uses the following external tools, drop in replacements can be inserted: 13 | # Curl: To fetch data from the interwebs 14 | # Install: See package manager. 15 | # MultiMonitorBackground: Set background wallpaper (multi monitor aware) 16 | # Install: https://github.com/DaveDavenport/MultiMonitorBackground 17 | ## 18 | 19 | # Directory of cache dir. 20 | CACHE_DIR=~/.cache/wallgig_collection/ 21 | # File holding ids of previous images. 22 | PREVIOUS_IDS_LIST=~/.wallgig_collection_prev_id 23 | # Command to set background. ${BG_SET_CMD} 24 | BG_SET_CMD="MultiMonitorBackground -clip -input" 25 | # command to fetch url and output to stdout. 26 | CURL="curl " 27 | 28 | WALLGIG_FUNCTIONS=wallgig.func 29 | if [ ! -f ${WALLGIG_FUNCTIONS} ] 30 | then 31 | echo "Failed to find: ${WALLGIG_FUNCTIONS}" 32 | exit 1; 33 | fi 34 | source wallgig.func 35 | 36 | # The collection to fetch images for. 37 | COLLECTION="682-qball-s-wallpapers" 38 | 39 | ## 40 | # Create cache directory 41 | ## 42 | if [ -n "${CACHE_DIR}" ] && [ ! -d ${CACHE_DIR} ] 43 | then 44 | mkdir -p "${CACHE_DIR}" 45 | fi 46 | 47 | if [ -z "${OFFLINE}" ] 48 | then 49 | ## 50 | # Construct Download URL 51 | ## 52 | URL="http://wallgig.net/collections/${COLLECTION}" 53 | 54 | echo "Fetching list of images." 55 | # Get list of IDS 56 | IDS=( $(download_ids "$URL") ) 57 | declare -i CONTINUE=1 58 | declare -i page=2 59 | while [[ ${CONTINUE} = 1 ]] 60 | do 61 | NEW_IDS=( $(download_ids "$URL?page=$page") ) 62 | echo "Got ${#NEW_IDS[@]} images: $page $URL&page=$page" 63 | if [[ ${#NEW_IDS[@]} = 0 ]] 64 | then 65 | CONTINUE=2; 66 | else 67 | IDS=( ${IDS[@]} ${NEW_IDS[@]} ) 68 | fi 69 | page=$page+1 70 | done 71 | 72 | 73 | echo "Got ${#IDS[@]} numbers" 74 | fi 75 | 76 | if [ -n "${DOWNLOAD}" ] 77 | then 78 | for IMAGE_ID in ${IDS[@]} 79 | do 80 | set_image "${IMAGE_ID}" 81 | done 82 | else 83 | # Check results 84 | if [ ${#IDS[@]} -eq 0 ] 85 | then 86 | if [ -n "${CACHE_DIR}" ] 87 | then 88 | IMAGE_ID=$(get_random_cache_image ) 89 | echo "Selected image from cache: ${IMAGE_ID}" 90 | echo ${IMAGE_ID} >> "${PREVIOUS_IDS_LIST}" 91 | cache_set_wallpaper "${IMAGE_ID}" 92 | exit 0; 93 | else 94 | echo "No Wallpapers found" 95 | exit 1; 96 | fi 97 | fi 98 | 99 | # Pick random image 100 | SELECTED_IMAGE=$(( ${RANDOM} % ${#IDS[@]} )) 101 | IMAGE_ID="${IDS[${SELECTED_IMAGE}]}" 102 | 103 | set_image "${IMAGE_ID}" 104 | fi 105 | -------------------------------------------------------------------------------- /wallgig_set_random_wallpaper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## 4 | # wallgig_set_random_wallpaper.sh 5 | # Written by: qball _at_ gmpclient _dot_ org 6 | # 7 | # Script fetches a random wallpaper from wallgig.net and sets this as background. 8 | # Preferences on what to display and what not to display can be specified. 9 | # 10 | # This script is public domain, you are free todo whatever you like with it. 11 | # The tools by this script are not! 12 | # 13 | # Script uses the following external tools: 14 | # Curl: To fetch data from the interwebs 15 | # Install: See package manager. 16 | # MultiMonitorBackground: Set background wallpaper (multi monitor aware) 17 | # Install: https://github.com/DaveDavenport/MultiMonitorBackground 18 | # xininfo: To get the width (pixels) of the biggest attached monitor. 19 | # Install: https://github.com/DaveDavenport/xininfo 20 | ## 21 | 22 | # Directory of cache dir. 23 | CACHE_DIR=~/.cache/wallgig/ 24 | # File holding ids of previous images. 25 | PREVIOUS_IDS_LIST=~/.wallgig_prev_id 26 | # Width of the largest monitor. 27 | WIDTH=$(xininfo --max-mon-width) 28 | # Command to set background. ${BG_SET_CMD} 29 | BG_SET_CMD="MultiMonitorBackground -clip -input" 30 | # command to fetch url and output to stdout. 31 | CURL="curl " 32 | 33 | 34 | WALLGIG_FUNCTIONS=wallgig.func 35 | if [ ! -f ${WALLGIG_FUNCTIONS} ] 36 | then 37 | echo "Failed to find: ${WALLGIG_FUNCTIONS}" 38 | exit 1; 39 | fi 40 | source wallgig.func 41 | 42 | # Number of pages to get. 43 | PAGE_NUMBERS=5 44 | 45 | ## 46 | # Wallgig configuration 47 | ## 48 | 49 | PURITY=sfw 50 | 51 | ## 52 | # Stuff we do not want to see 53 | ## 54 | EXCLUDE_TAGS=( 'anime' 'anime-girls' 'anime+girls' 'cleavage' ) 55 | 56 | EXCLUDE_CATEGORIES=( 'People' 'Games' 'Vehicles' 'Anime+%2F+Manga') 57 | 58 | ## 59 | # Stuff we do want to see 60 | ## 61 | TAGS=( 'flags' 'road' 'nature' 'landscapes' 'ocean' 'forest' 'roads' 'forests' 'landscape' 'cityscape') 62 | 63 | 64 | ## 65 | # Create cache directory 66 | ## 67 | if [ -n "${CACHE_DIR}" ] && [ ! -d ${CACHE_DIR} ] 68 | then 69 | mkdir -p "${CACHE_DIR}" 70 | fi 71 | 72 | ## 73 | # Construct Download URL 74 | ## 75 | URL="http://wallgig.net/?order=random&per_page=40&purity\[\]=${PURITY}" 76 | 77 | 78 | # Add exclude tags. 79 | for ET in ${EXCLUDE_TAGS[@]} 80 | do 81 | URL="${URL}&exclude_tags\[\]=${ET}" 82 | done 83 | 84 | # Add exclude categories. 85 | for EC in ${EXCLUDE_CATEGORIES[@]} 86 | do 87 | URL="${URL}&exclude_categories\[\]=${EC}" 88 | done 89 | 90 | #Pick a random tag we want to show. 91 | 92 | URL="${URL}&tags%3A(" 93 | for TAG in ${TAGS[@]} 94 | do 95 | if [ $TAG = ${TAGS[$((${#TAGS[@]}-1))]} ] 96 | then 97 | URL="${URL}${TAG})" 98 | else 99 | URL="${URL}${TAG}+OR+" 100 | fi 101 | done 102 | 103 | # Set width preferences 104 | if [ -n ${WIDTH} ] 105 | then 106 | URL="${URL}&width=${WIDTH}" 107 | fi 108 | 109 | echo "Fetching list of images." 110 | # Get list of IDS 111 | IDS=( $(download_ids "$URL") ) 112 | 113 | 114 | for page in `seq 1 ${PAGE_NUMBERS}` 115 | do 116 | IDS=( ${IDS[@]} $(download_ids "$URL&page=$page") ) 117 | done 118 | 119 | echo "Got ${#IDS[@]} numbers" 120 | 121 | # Check results 122 | if [ ${#IDS[@]} -eq 0 ] 123 | then 124 | if [ -n "${CACHE_DIR}" ] 125 | then 126 | IMAGE_ID=$(get_least_viewed_cache_image ) 127 | echo "Selected image from cache: ${IMAGE_ID}" 128 | echo ${IMAGE_ID} >> "${PREVIOUS_IDS_LIST}" 129 | cache_set_wallpaper "${IMAGE_ID}" 130 | exit 0; 131 | else 132 | echo "No Wallpapers found" 133 | exit 1; 134 | fi 135 | fi 136 | 137 | # Pick random image 138 | SELECTED_IMAGE=$(( ${RANDOM} % ${#IDS[@]} )) 139 | IMAGE_ID="${IDS[${SELECTED_IMAGE}]}" 140 | 141 | set_image "${IMAGE_ID}" 142 | -------------------------------------------------------------------------------- /weathernl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | LATITUDE=52.09 4 | LONGITUDE=5.11 5 | 6 | NOW=$(date +%s) 7 | declare -A WEATHER; 8 | function dl() 9 | { 10 | curl "http://gps.buienradar.nl/getrr.php?lat=${LATITUDE}&lon=${LONGITUDE}" 2>/dev/null | tr -d '\r' 11 | } 12 | 13 | RAINING=false 14 | STOP=0 15 | START=0 16 | 17 | function get_prediction() 18 | { 19 | while read A 20 | do 21 | SM=(${A//\|/ }) 22 | 23 | echo $A 24 | STIME=$(date +%s -d ${SM[1]}) 25 | DTIME=$(( ($STIME-$NOW)/60 )) 26 | if [ ${DTIME} -le 0 ] && [ ${DTIME} -gt -5 ] 27 | then 28 | if [ ${SM[0]} -gt 0 ] 29 | then 30 | RAINING=true 31 | fi 32 | fi 33 | # Bash does not like 0 padded integers. 34 | VALUE=$(echo ${SM[0]} | bc ) 35 | 36 | if [ ${DTIME} -gt 0 ] 37 | then 38 | if ${RAINING} && [ ${VALUE} -eq 0 ] && [ ${STOP} -eq 0 ] 39 | then 40 | STOP=${DTIME} 41 | fi 42 | if ! ${RAINING} && [ ${VALUE} -gt 0 ] && [ ${START} -eq 0 ] 43 | then 44 | START=${DTIME} 45 | fi 46 | fi 47 | done < <(dl) 48 | 49 | } 50 | 51 | get_prediction 52 | 53 | if ${RAINING} 54 | then 55 | echo "It is raining" 56 | if [ ${STOP} -gt 0 ] 57 | then 58 | echo "It will stop in ${STOP} minutes." 59 | else 60 | echo "It won't stop for the next 2 hours." 61 | fi 62 | fi 63 | if ! ${RAINING} 64 | then 65 | echo "It is not raining" 66 | if [ ${START} -gt 0 ] 67 | then 68 | echo "It will start in ${START} minutes." 69 | else 70 | echo "It won't start for the next 2 hours." 71 | fi 72 | fi 73 | --------------------------------------------------------------------------------