You are not logged in.

#3076 2017-11-04 21:28:23

Mladia
Member
Registered: 2016-04-30
Posts: 32

Re: Post your handy self made command line utilities

Reading the current marked word and google-ing it. I've assigned the script to a keyboard shortcut and can easly search something.


googwo

#!/bin/bash

word=$(xclip -out -selection primary)

echo $word | xclip -in -selection clipboard

url="https://www.google.de/search?q=$word"

xdg-open "$url" &

The variables are a little bit redundant and can be done in a one-liner, but it's easier for to read and copy stuff from it.

Offline

#3077 2017-11-04 22:20:07

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 42

Re: Post your handy self made command line utilities

Mladia wrote:
xdg-open "$url" &

It's possible to replace shell process instead of creating new one:

exec xdg-open "$url"

Not so important but little bit more optimal.

Offline

#3078 2017-11-05 14:40:10

YesItsMe
Member
Registered: 2017-07-12
Posts: 25

Re: Post your handy self made command line utilities

I made a simple client for the twtxt micro-blogging system:
https://hub.darcs.net/dertuxmalwieder/twtxtc

Offline

#3079 2017-11-12 15:39:17

quequotion
Member
From: Oita, Japan
Registered: 2013-07-29
Posts: 567
Website

Re: Post your handy self made command line utilities

Execute a command after a desktop notification countdown:

#!/bin/bash
#usage: countdown "command -argument -argument" "number"
TIMER="${2}"
while [ "${TIMER}" -gt 0 ]; do
  [[ "${TIMER}" -eq "${2}" ]] && replace="$(notify-send -u critical -t 900 -i media-playback-pause -p -- ${TIMER})"
  [[ "${TIMER}" -lt "${2}" ]] && replace="$(notify-send -u critical -t 900 -i media-playback-pause -r ${replace} -p -- ${TIMER})"
  TIMER="$(($TIMER-1))"
  sleep 1
done
#echo "GO!"
command ${1}

You'll need a notification daemon that respects the timeout parameter as well as {print,replaces} id parameters. I use notify-osd-customizable; it's timeout support is partial and notifications tend to linger on or vanish early by some milliseconds. The resulting countdown has an almost human inaccuracy.

Another daemon might yield more precise countdowns.

Edit: "-u critical" might be necessary for notify-osd(-customizable).

Last edited by quequotion (Yesterday 02:40:13)

Offline

#3080 2017-11-15 04:46:36

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 23,669
Website

Re: Post your handy self made command line utilities

Updating Ambrevar's handy currency converter after Google changed their URLs.

#!/bin/sh
# from Ambrevar https://bbs.archlinux.org/viewtopic.php?pid=1568235#p1568235

if [ $# -ne 3 ] || [ "$1" = "-h" ]; then
	cat <<EOF
Usage: ${0##*/} VALUE IN-CURRENCY OUT-CURRENCY

Convert VALUE from IN-CURRENCY to OUT-CURRENCY.
CURRENCY is a 3-letters code like EUR, SEK, USD, etc.

EOF
	exit
fi
curl -sA "Mozilla/5.0" "https://finance.google.com/finance/converter?a=$1&from=$2&to=$3" | \
    awk -F '<|>' '/result/ {print substr($5,1,length($5)-6)}'

Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#3081 2017-11-18 21:04:55

Ambrevar
Trusted User (TU)
Registered: 2011-08-14
Posts: 209
Website

Re: Post your handy self made command line utilities

Not using GNU units?

Offline

#3082 2017-11-18 21:17:33

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 23,669
Website

Re: Post your handy self made command line utilities

Units is awesome for static conversions (pounds to kilos), but for currencies I found this approach much more accurate.


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#3083 2017-11-20 18:14:30

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 42

Re: Post your handy self made command line utilities

Script for switching secondary monitor on/off. It's binded to a key in window manager.

#!/bin/sh

OUTPUT=VGA-0

STATE=$(xrandr | grep "^${OUTPUT}" | sed -n 's/.*\(connected\|disconnected\)[[:space:]]\+\(primary\)\?\([^(]\+\)(.*/\3/p')

if [ -n "${STATE}" ]; then
    MODE="--off"
else
    MODE="--mode 1280x1024 --pos 1920x176 --rotate normal"
fi

xrandr --output "${OUTPUT}" ${MODE}

Offline

#3084 2017-11-20 19:16:30

Trilby
Forum Fellow
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 17,446
Website

Re: Post your handy self made command line utilities

No need to pipe through grep to sed, sed can use a line regex.  But in this case it looks like you are just checking whether or not there is a number before the parentheses, so there is no need for sed at all:

OUTPUT=VGA-0
MODE="--mode 1280x1024 --pos 1920x176"

xrandr | grep -q "^${OUTPUT}[ a-z]*[0-9]" && MODE="--off"
xrandr --output $OUTPUT $MODE

Last edited by Trilby (2017-11-21 02:23:04)


Resist the GNU world order.

Offline

#3085 2017-11-21 02:18:56

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 42

Re: Post your handy self made command line utilities

Trilby wrote:

No need to pipe through grep to sed, sed can use a line regex.

Thank you for reply.
Of course it can be optimized. It was just a quick&dirty solution.

Trilby wrote:

But in this case it looks like you are just checking whether or not there is a number before the parentheses, so there is no need for sed at all:

xrandr | grep "^${OUTPUT}[ a-z]*[0-9]"

Yes, that's better. Xrandr output is for humans and isn't strict. I don't know can it be different in other versions, localizations etc.

Offline

Board footer

Powered by FluxBB