You are not logged in.
I guess not - just another option. A link just seemed simpler than parsing the file, but no real difference.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
It probably is (simpler); I just hadn't thought of it...
Offline
I just have one static wallpaper "file" with no name extention. It's just called "wallpaper" and is a symlink to whatever wallpaper I currently use. This link is used by the background setter, the screensaver and i3-lock. The moment you add another program, that calls this file, the less complicated it gets with a symlink. In your case, however, the only reason to prefer a symlink is, that anything, that changes a "critical" file like .xinitrc might corrupt that file in some edge cases.
But I think Trilby meant, that all that sed and awk is not very elegant here and that the symlink approach could solve this in half the lines. :-)
EDIT: Okay, I'm late to the show. Nevermind then.
Last edited by Awebb (2013-08-11 10:23:57)
Offline
display -window root -size 0000x000 ~/.local/share/wall
Can even handle .webp formats.
I find it hard to believe anyone doesn't have imagemagick or graphicsmagick installed.
Offline
I find it hard to believe anyone doesn't have imagemagick or graphicsmagick installed.
https://www.archlinux.de/?page=PackageStatistics (the page is a bit big, may load a while)
* imagemagick 85.99 %
* graphicsmagick 22.67 %
Offline
display -window root -size 0000x000 ~/.local/share/wall
I'm actually rather interested in using this option to display my wallpaper instead of `feh` as I, also, am trying to switch over to sxiv. However, I'm having some trouble with that -size argument. It doesn't seem to be correctly sizing the image. Instead, the image is scaled so that the height fits which then repeats the image as tiles. The argument to size is meant to be the pixel counts (width and height) for which the image should be displayed, right?
All the best,
-HG
Offline
Kaustic wrote:I find it hard to believe anyone doesn't have imagemagick or graphicsmagick installed.
https://www.archlinux.de/?page=PackageStatistics (the page is a bit big, may load a while)
* imagemagick 85.99 %
* graphicsmagick 22.67 %
Those statistics are far from true or accurate or even up to date. They're fun though
The argument to size is meant to be the pixel counts (width and height) for which the image should be displayed, right?
The -size parameter is usually given when the size of an image isn't known (RAW) or to override the information in the image header. It's mostly unnecessary in this case as display automatically scales the image to fit the root window's dimensions.
Last edited by Earnestly (2013-08-11 17:21:30)
Offline
The -size parameter is usually given when the size of an image isn't known or to override the information in the image header. It's mostly unnecessary in this case as display automatically scales the image to fit the root window's dimensions.
But, it appears to fit the image to the height of the window, not the width, correct? Is there a way to reverse this?
All the best,
-HG
Offline
I've never used `display`, but most other imagemagick tools will preserve the aspect ratio while scaling (by default), so the smaller scale axis is used for both. Usually a '!' after the size will scale to the exact size ignoring aspect ratio. Otherwise, if you don't mind the top/bottom being cut off, you can just put a very large height and set the width to your screen width. Then the image will be scaled (vertically and horizontally) with a scale factor to fit the width to the screen.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I'm not sure, try asking on ##imagemagick on freenode or reading the documentation. I would be surprised if it couldn't.
Edit: Ahh, Trilby has already provided an idea. -gravity center may work but I haven't tested.
/me still has to learn a lot about the power of imagemagick.
Last edited by Earnestly (2013-08-11 18:17:01)
Offline
Slight modification of dmenu_run that pipes the output through xargs:
#!/bin/sh
# usage: dmenu_xargs <command> <dmenu_run args>
cmd="$1"; shift 1
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
cache=$cachedir/dmenu_xargs
else
cache=$HOME/.dmenu_cache
fi
( IFS=:
if stest -dqr -n "$cache" $PATH; then
stest -flx $PATH | sort -u | tee "$cache" | dmenu -p "$cmd" "$@"
else
dmenu -p "$cmd" "$@" < "$cache"
fi
) | xargs -0 $cmd
It also defaults to using the command as the prompt name. I use it with i3 to have a variety of prompts in addition to regular dmenu_run:
# ~/.config/i3/config
# dmenu prompts
bindsym $mod+r dmenu_run
bindsym $mod+n dmenu_xargs i3-rename
bindsym $mod+b dmenu_xargs xbacklight
etc.
EDIT: Oh, and i3-rename is this:
#!/bin/bash
i3-msg "rename workspace to \"$@\""
Last edited by jefdaj (2013-08-13 21:25:46)
Offline
If you use PowerDNS as your nameserver, then this script provides an easy way to manage dynamic DNS:
https://github.com/battlesnake/ddns
Includes a hacky web interface to manage your dynamic DNS remotely (and of course, for updating the dynamic IP address via a curl command!)
If you access your home PC a lot from work/other external networks, but don't want to run up an energy bill, then turn a Raspberry Pi into a wake-on-lan proxy:
https://github.com/battlesnake/macs
(note: via cron job, also maintains a list of machines detected on your network, with IP/hostname/MAC address, so you don't have to remember your PC's MAC address)
Last edited by windows_me (2013-08-14 11:34:57)
[10:04:21] Time for weekly full server backup.
[10:04:25] Redirecting it to "/dev/null" to make it go faster.
[10:04:53] Backup done! Amazing how fast modern technology is!
Offline
Just a handy vnc script I wrote to deal with the whole xauth thing.
#!/usr/bin/bash
# Run this command as root
CURRENTUSER=$(ps -u|sed -n 2p|awk '{print $1}')
if [ "$CURRENTUSER" == "root" ]; then
X11AUTH=$(ps x|grep X|awk '{print $14}')
echo $X11AUTH
x11vnc -forever -rfbport $1 -display :0 -auth $X11AUTH
else
echo "You must be root to run this command"
fi
Edit: You may need to edit the awk like depending on your display manager. kdm has it in the 14th column but gdm-old has it in column 10. Also thanks for the $USER and $UID tip.
Last edited by wstewart90 (2013-08-15 06:05:06)
Offline
you can use $USER or better $UID to detect if you're not root
Linux odin 3.13.1-pf #1 SMP PREEMPT Wed Mar 5 21:47:28 CET 2014 x86_64 GNU/Linux
Offline
or whoami
Offline
After getting frustrated trying to find a TV episode downloader, I hacked together the following script. Anyone know of something similar?
#!/bin/bash
# Script to automatically scrape the kickass.to rss feed for tv episodes.
# Place episode configuration files with a .dl extension in same directory.
# Sample .dl file is shown below. Script will source the .dl files one by one,
# and search for the episode by the variable URI. Results are filtered by
# variable MINSEEDS, and sorted to accept only the highest seeded match. If
# found, magnet is posted to transmission, and the EPISODE number in the .dl
# file is incremented.
#
# Dependencies: Script uses "transmission-cli", "curl", "xmlstarlet" for command "xml"
# Todo: season increment logic, download .torrent file to a "watch" directory
#
# Example:
# Search for "burn notice 720p s07e10"
# file: burnNotice.dl
# ##################
# SEASON=7
# EPISODE=10
# SEASON0=`printf "%0*d" 2 ${SEASON}`
# EPISODE0=`printf "%0*d" 2 ${EPISODE}`
# URI="http://kickass.to/usearch/burn%20notice%20720p%20s${SEASON0}e${EPISODE0}/?rss=1"
# ##################
# authentication for transmission-remote
AUTH=user:password
# filter torrents with less than MINSEEDS
MINSEEDS=2
FILES=*.dl
for file in $FILES
do
. $file
echo curling rss feed of $file for s${SEASON0}e${EPISODE0}
# xml command sorts descending on torrent:seeds where torrent:seeds >= $MINSEEDS
MAGNET=$(curl --connect-timeout 2 -s "$URI" | xml sel -T -t -m /rss/channel/item -s D:N:- torrent:seeds -i "torrent:seeds>=$MINSEEDS" -v torrent:magnetURI 2>/dev/null)
if [ "$MAGNET" != "" ]; then
echo adding magnet to transmission...
transmission-remote -n $AUTH -a "$MAGNET"
if [ "$?" == "0" ]; then
echo incrementing episode number
SEDEX="s/^EPISODE=$EPISODE$/EPISODE=$(($EPISODE+1))/"
sed "$SEDEX" -i $file
else
echo failed to submit magnet
fi
else
echo failed to get magnet
fi
# give rss server a break
sleep 1
done
Offline
or whoami
using a var is faster than calling an external command, but if you using a posix shell than this would be what I do.
Here my function to calculate on shell:
rechner() {
echo "$@" | bc -l
}
Linux odin 3.13.1-pf #1 SMP PREEMPT Wed Mar 5 21:47:28 CET 2014 x86_64 GNU/Linux
Offline
Here my function to calculate on shell:
rechner() { echo "$@" | bc -l }
I suggest using e.g.
echo "scale=3;$@" | bc -l
for your ordinary calculations, like '20/7'.
Offline
Thaodan wrote:Here my function to calculate on shell:
rechner() { echo "$@" | bc -l }
I suggest using e.g.
echo "scale=3;$@" | bc -l
for your ordinary calculations, like '20/7'.
Thanks I extended it a bit:
rechner() {
local arg scale=3 ;
while getopts s: arg ; do
case $arg in
s) scale=$OPTARG;
esac
done
shift $((OPTIND-1))
echo "scale=$scale;$@" | bc -l
}
Linux odin 3.13.1-pf #1 SMP PREEMPT Wed Mar 5 21:47:28 CET 2014 x86_64 GNU/Linux
Offline
repeat.sh - Repeat command $x times after $y interval
if [[ "$1" =~ ^[0-9]+$ ]] && [[ "$2" =~ ^[0-9]+$ ]]; then
max=$1
count=$2
shift
shift
for ((i=1; i <= max ; i++)); do
sleep $count
eval "$@"
done
else
echo "Usage: $0 [count] [interval] command"
fi
Offline
eval "$@"
Don't do eval, not here. Simply "$@". Hint: repeat.sh 2 0 echo '$(:)'
This silver ladybug at line 28...
Offline
python -m http.server <port>
shares the current directory via HTTP over a certain port. Ctrl+C to stop sharing.
To make this nicer, try the following:
echo 'python -m http.server $1' | sudo tee /usr/bin/share && sudo chmod +x /usr/bin/share
Then to share a folder temporarily, just use:
share <port>
Ctrl+C is still of course used to stop the server.
To run the server in the background, use
share <port> &
Then to stop it, use your favourite syntax of the kill command.
Note that you need root permission to use a port less than 1024.
Last edited by windows_me (2013-08-27 15:58:09)
[10:04:21] Time for weekly full server backup.
[10:04:25] Redirecting it to "/dev/null" to make it go faster.
[10:04:53] Backup done! Amazing how fast modern technology is!
Offline
If anyone can use this.
A couple of scripts that I wrote for Google text to speech, and Google text to text translation.
They work from shell and allow you to translate until you quit.
The text to speech script concatenates to $FILE.mp3 so you can make a single file out of 100 char max. segments. The text to text dumps the output to sdout, redirect to $FILE if you want.
You might want to take it easy on how many times a minute you hit their server.
Text to text
#! /usr/bin/env bash
# Translate text using google. No google account needed.
# Requires curl, awk, iconv, html2text
# Language are:
# af ar az be bn bg bs ca cub zh-CN zh-TW cs cy da de en en_us en_gb en_au
# el es et eu fa fi fr ga gl gu ht hi hmn hr hu hy is id it iw ja jw ka km
# kn ko la lv lt mk mr ms mt no nl pl pt ro ru sr sk sl sq sw sv ta te th tl
# tr uk ur vi yi
clear
OPTIONS="Input_Lang Output_Lang Enter_Text Translate Quit"
echo "Press Enter at any time to return to menu."
echo "Select an option:"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
clear
exit
elif [ "$opt" = "Input_Lang" ]; then
echo "Language options are:"
echo "en de fr es it" # Add languages here.
echo "What input language"
read ILAN
elif [ "$opt" = "Output_Lang" ]; then
echo "Language options are:"
echo "en de fr es it" # Add languages here.
echo "What ouput language"
read OLAN
elif [ "$opt" = "Enter_Text" ]; then
echo "Enter text"
read TEXT
elif [ "$opt" = "Translate" ]; then
result=$(curl -s -i --user-agent "" -d "sl=$ILAN" -d "tl=$OLAN" --data-urlencode "text=$TEXT" http://translate.google.com)
encoding=$(awk '/Content-Type: .* charset=/ {sub(/^.*charset=["'\'']?/,""); sub(/[ "'\''].*$/,""); print}' <<<"$result")
iconv -f $encoding <<<"$result" | awk 'BEGIN {RS="</div>"};/<span[^>]* id=["'\'']?result_box["'\'']?/' | html2text
else
echo "Bad option"
fi; done
Text to voice
#! /usr/bin/env bash
# Text to speech conversion using google text to voice. No google account needed.
# Requires wget
# 100 char. max. Output to "$NAME.mp3"
# Language are:
# af ar az be bn bg bs ca cub zh-CN zh-TW cs cy da de en en_us en_gb en_au
# el es et eu fa fi fr ga gl gu ht hi hmn hr hu hy is id it iw ja jw ka km
# kn ko la lv lt mk mr ms mt no nl pl pt ro ru sr sk sl sq sw sv ta te th tl
# tr uk ur vi yi
clear
OPTIONS="Language Enter_Text Filename Translate Quit"
echo "Press Enter at any time to return to menu."
echo "Select an option:"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
clear
exit
elif [ "$opt" = "Language" ]; then
echo "Language options are:"
echo "en de fr es it" # Add languages here.
echo "What Language?"
read LNG
elif [ "$opt" = "Enter_Text" ]; then
echo "Enter text to translate to voice"
read WORDS
elif [ "$opt" = "Filename" ]; then
echo "Output file name?"
read NAME
elif [ "$opt" = "Translate" ]; then
URL="http://translate.google.com/translate_tts?tl=${LNG}&q="
wget -q -U Mozilla -O - "$URL""$WORDS" >> "$NAME".mp3
else
echo "Bad option"
fi; done
Offline
inspired from this but with bookmarks in a text file :
mark() {
echo "$1|$(pwd)" >> $HOME/.marks
}
unmark() {
sed "/^$1|/d" $HOME/.marks -i
}
jump() {
dir=$(grep $1 $HOME/.marks)
dir=${dir/*|/}
cd $dir
}
# this is for zsh :
function _completemarks {
reply=($(sed 's/\(.*\)|.*/\1/' $HOME/.marks))
}
compctl -K _completemarks cdm
compctl -K _completemarks delmark
Offline
A simple wrapper for the surf browser, which removes the cookies.txt file (where surf stores its cookies) when surf exits.
#!/usr/bin/env bash
# start surf
/usr/bin/surf "$@"
# get pid
surf_running=$(pidof surf)
# if surf is not running, remove the cookies file
if [[ -z $surf_running ]]; then
/usr/bin/rm "$HOME"/.surf/cookies.txt
/usr/bin/rm -rf "$HOME"/.local/share/webkit
fi
Edit: Added the webkit directory. It has the localstorage crap and other unneeded stuff.
Last edited by x33a (2013-09-18 18:05:44)
Offline