You are not logged in.

#451 2009-08-04 05:23:37

hidefromkgb
Member
Registered: 2009-08-03
Posts: 146

Re: Post your handy self made command line utilities

Being fed up with XScreensaver's lack of proper API for switching on/off, I decided not to use "heartbeat_cmd" command in MPlayer (because it results in serious glitches during playback), and invented a simple script called "sm". Here it is:

#!/bin/sh
rm ~/.xscreensaver; ln -s ~/.config/xscr-stub ~/.xscreensaver; (xscreensaver-command -restart &); smplayer $@
if top -b -n1|grep -q smplayer; then true; else rm ~/.xscreensaver; ln -s ~/.config/xscr-main ~/.xscreensaver; (xscreensaver-command -restart &) fi

As you see, it requires two files in .config subdirectory of your home dir. First is xcsr-main - a "normal" XScreensaver config. Second is xscr-stub - a config that says XScreensaver is switched off.
When an instance of SMPlayer is closed, the script does not switch XScreensaver on unless it was the last instance.


[offtop]
BTW, Themaister, your music is cool! I think I'm your fan now big_smile
[/offtop]

Last edited by hidefromkgb (2009-08-04 05:24:52)

Offline

#452 2009-08-04 08:08:26

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 370

Re: Post your handy self made command line utilities

Heller_Barde wrote:

I hope you don't mind, I rewrote your little script (which i like very much btw) to use zenity (this is purely a personal preference) and not to use a temporary file. I thought you might like it smile

Nice Phil, I will have to try it out. Surely, your script must be "better" than mine. At least you made an active choice on which GTK+ window drawer to use. I just use the only one I knew about smile

anrxc wrote:

I also liked the idea and also wrote my own, in python. Pypres is a small utility for enabling external displays based on presets, intended to be used with the "Presentation" media button found on many laptops.

It looks very neat. Is there any advantage in using Python for this? I think Emacs support Python out of the box so I might also have a look at your script. If nothing else than for the cool logo smile


Arch x64 on Thinkpad X200s/W530

Offline

#453 2009-08-04 14:35:27

Themaister
Member
From: Horten, Norway
Registered: 2008-07-21
Posts: 647
Website

Re: Post your handy self made command line utilities

hidefromkgb wrote:

Being fed up with XScreensaver's lack of proper API for switching on/off, I decided not to use "heartbeat_cmd" command in MPlayer (because it results in serious glitches during playback), and invented a simple script called "sm". Here it is:

#!/bin/sh
rm ~/.xscreensaver; ln -s ~/.config/xscr-stub ~/.xscreensaver; (xscreensaver-command -restart &); smplayer $@
if top -b -n1|grep -q smplayer; then true; else rm ~/.xscreensaver; ln -s ~/.config/xscr-main ~/.xscreensaver; (xscreensaver-command -restart &) fi

As you see, it requires two files in .config subdirectory of your home dir. First is xcsr-main - a "normal" XScreensaver config. Second is xscr-stub - a config that says XScreensaver is switched off.
When an instance of SMPlayer is closed, the script does not switch XScreensaver on unless it was the last instance.


[offtop]
BTW, Themaister, your music is cool! I think I'm your fan now big_smile
[/offtop]

Aha big_smile Thanks.

Offline

#454 2009-08-05 16:46:32

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Post your handy self made command line utilities

A small script to convert AVI files in to a DVD.

#!/bin/bash
##$1=input file
##$2=output file 
mkdir $2
/usr/bin/mencoder -srate 48000 -af lavcresample=48000 -speed 25025:24000 -oac lavc -aid 1 -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -ofps 25 -vf expand=640:360:0:44,scale=720:576,harddup -lavcopts threads=2:vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:vrc_maxrate=8500:vrc_buf_size=1835:vbitrate=5001:keyint=12:acodec=ac3:abitrate=224:aspect=16/9 -o $2/$2.mpg $1
cd $2
dvdauthor -o $2 -t *.mpg
dvdauthor -o $2 -T
mkisofs -dvd-video -o $2.iso $2/
wodim -v dev=/dev/cdrom $2.iso

Usage: dvdconvert.sh /path/to/file.avi  outputname   

i just came up with this to day, its in the middle of burning the disk, im confident it will play in a dvd player, but im gona test the disk, then report back.

edit0: it plays, but it has messed up the size of the screen, insted of having 2 bars, 1 at the top and bottom. it has a giant black bar at the bottom, How do i make mencoder encode the video without changing the aspect ratio or moving the black bars around?

edit1: i have changed the mencoder options, it should work better now

Last edited by markp1989 (2009-08-05 18:05:03)


Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

#455 2009-08-05 22:11:36

scragar
Member
Registered: 2009-07-14
Posts: 108

Re: Post your handy self made command line utilities

markp1989 wrote:

A small script to convert AVI files in to a DVD.

#!/bin/bash
##$1=input file
##$2=output file 
mkdir $2
/usr/bin/mencoder -srate 48000 -af lavcresample=48000 -speed 25025:24000 -oac lavc -aid 1 -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -ofps 25 -vf expand=640:360:0:44,scale=720:576,harddup -lavcopts threads=2:vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:vrc_maxrate=8500:vrc_buf_size=1835:vbitrate=5001:keyint=12:acodec=ac3:abitrate=224:aspect=16/9 -o $2/$2.mpg $1
cd $2
dvdauthor -o $2 -t *.mpg
dvdauthor -o $2 -T
mkisofs -dvd-video -o $2.iso $2/
wodim -v dev=/dev/cdrom $2.iso

Usage: dvdconvert.sh /path/to/file.avi  outputname   

i just came up with this to day, its in the middle of burning the disk, im confident it will play in a dvd player, but im gona test the disk, then report back.

edit0: it plays, but it has messed up the size of the screen, insted of having 2 bars, 1 at the top and bottom. it has a giant black bar at the bottom, How do i make mencoder encode the video without changing the aspect ratio or moving the black bars around?

edit1: i have changed the mencoder options, it should work better now

Very nice code, I've not taken a real look too much into it yet, but please try this edit, which I made so I can run it right from nautilus:

#!/bin/bash
cd $(dirname "$1"); ## this makes things easier later on.
in=$(basename "$1"); ## because otherwise .'s in directories cause problems
out=${in%.*}; ## here.

mkdir "$out"

/usr/bin/mencoder -srate 48000 -af lavcresample=48000 -speed 25025:24000 -oac lavc -aid 1 -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -ofps 25 -vf expand=640:360:0:44,scale=720:576,harddup -lavcopts threads=2:vcodec=mpeg2video:trell:mbd=2:sc_threshold=1000000000:cgop:vstrict=0:vrc_maxrate=8500:vrc_buf_size=1835:vbitrate=5001:keyint=12:acodec=ac3:abitrate=224:aspect=16/9 -o "$out/$out.mpg" "$in"

cd "$out"

dvdauthor -o "$out" -t *.mpg
dvdauthor -o "$out" -T

mkisofs -dvd-video -o "../$out.iso" "$out/"
cd ..
rm -rf "$out"

I'm planning to edit this again to handle converting multiple files at the same time(so you can highlight multiple files at once and convert them in sequence to the DVD), but I have no idea how to do that, I was thinking of dividing it up, first I create a small text file, if it exists I append to it. After say, one second, if no new changes have been made to the file we lock the file and start converting them all, if not we exit early, and leave it for whichever version of the application wrote to the file last(giving most time for other files being added incase it's running a little slow).

I'm sure there's a much better method though.


EDIT:
After testing I found some interference on the right hand side, any help fixing that? I have no idea what's causing it or what settings I'd change to fix it.

Last edited by scragar (2009-08-05 22:19:24)

Offline

#456 2009-08-06 22:20:49

Wintervenom
Member
From: /home/wintervenom
Registered: 2008-08-20
Posts: 1,011
Website

Re: Post your handy self made command line utilities

#!/bin/bash

### Magic Eight-Ball ############################################
# Version 0.2 by Scott Garrett <wintervenom [(a)] archlinux.us> #
#################################################################

responses=(
    'As I see it, yes'
    'It is certain'
    'It is decidedly so'
    'Most likely'
    'Outlook good'
    'Signs point to "yes"'
    'Without a doubt'
    'Yes'
    'Yes, definitely'
    'You may rely on it'
    'Reply hazy, try again'
    'Ask again later'
    'Better not tell you now'
    'Cannot predict now'
    'Concentrate and ask again'
    "Don't count on it"
    'My reply is "no"'
    'My sources say "no"'
    'Outlook not so good'
    'Very doubtful'
    'You are a fucktard.  Suicide would be best.'
)

punctuation=('.' '!')

response="      ${responses[((RANDOM % 20))]}${punctuation[((RANDOM % 2))]}      "

ball="
   OOOOOOOO
 OO        OO
 O  .::::.  O
O  ..    ..  O
O  .      .  O
O  ..    ..  O
 O  '::::'  O
 OO        OO
   OOOOOOOO
"

tcols=`tput cols`
trows=`tput lines`

tput init
echo "$ball"

function shake() {
    tput cup 0 0
    for ((x=0; x<10; x++)); do
        tput il 1
        sleep 0.01
    done
    tput cup $trows 0
    for ((x=0; x<10; x++)); do
        echo
        sleep 0.005
    done
}
shake
shake
shake
for ((x=0; x<5; x++)); do
    tput il 1
    sleep 0.01
done

len=${#response}
for ((x=0; x<len-5; x++)); do
    tput cup 5 4
    echo "${response:x:6}"
    sleep 0.1
done

tput cup 11 0

My [GitHub] and my [artwork].
Data is guaranteed to stay crunchy in milk.
Keep your _✍ hand strong.

Offline

#457 2009-08-06 22:44:11

Heller_Barde
Member
Registered: 2008-04-01
Posts: 245

Re: Post your handy self made command line utilities

Wintervenom wrote:
#!/bin/bash

len=${#response}
for ((x=0; x<len-5; x++)); do
    tput cup 6 4
    echo "${response:x:6}"
    sleep 0.1
done

on my console there is a little bug, I need to change

tput cup 5 4

to

tput cup 6 4

like above

Offline

#458 2009-08-08 10:05:36

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,221
Website

Re: Post your handy self made command line utilities

This script checks for new mail and starts mutt if there's any.

#!/bin/bash

M=$(getmail | tail -1 | sed 's/[a-z]//g' | head -c 4)

if(("$M" > "0")); then
        mutt
else
        printf "\033[0;31mNo new mails\n";exit
fi

Offline

#459 2009-08-11 23:14:26

Killa B
Member
From: United States
Registered: 2008-10-28
Posts: 42
Website

Re: Post your handy self made command line utilities

Upload a file to ftp:

#!/bin/sh
user='username'
pass='password'
domainftp='example.com/b/'
domainhttp='http://example.com/b/'
 
wput "$1" "ftp://${user}:${pass}@${domainftp}$1" &> /dev/null
echo "${domainhttp}$1"

Offline

#460 2009-08-12 14:43:20

kourosh
Member
From: England
Registered: 2009-03-10
Posts: 241
Website

Re: Post your handy self made command line utilities

This has probably been done before, but I felt the need to script something, basic twitter status updater, uses zenity if no argument is given, if given an argument, the command line version will be invoked.

#!/bin/bash

# twitterupd: Twitter Updater
# Written badly by Kourosh Parsee 09/08/2009

MESSAGE=$1
username=
password=

gui() {
    ZMESSAGE=$(zenity --entry --title="Update Twitter" --ok-label="Update" --text "What are you doing?") || exit 0
    curl --basic --user $username:$password --data status="$ZMESSAGE" http://twitter.com/statuses/update.xml > /dev/null || zenity --error --text="Status Update Failed"
    zenity --info --text="Status Updated"
    exit 0
}

basic() {
    echo -n "You are about to set your status to: "
    echo "$MESSAGE"
    echo -n "Continue? (y/n) "
    read yn
    if [ $yn = "y" ]; then
        echo "Updating Twitter..."
        curl --basic --silent --user $username:$password --data status="$MESSAGE" http://twitter.com/statuses/update.xml > /dev/null || echo "Status Update Failed"
        echo "Status Updated"
    else
        exit 0
    fi
}

if [ "$1" = "" ]; then
    gui
else
    basic
fi

Offline

#461 2009-08-12 16:03:27

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

if you use remind (+ wyrd ftw!) as your linux calendar app, and you have a public gcal, then you can use this in a cron job to sync your google calendar to your .reminders file.  it's a simple one-way sync but it works for me.

requires ical2rem.pl and the perl-ical-parser package.

#!/bin/sh
#
##

REM="$HOME/.reminders"
CON="$HOME/.bin/ical2rem.pl"
URL="http://www.google.com/calendar/ical/GMAILUSERNAME%40gmail.com/public/basic.ics"

wget -q -O - "$URL" | $CON > $REM

the perl script does all the work, my bash wrapper just downloads the public gcal ical file before hand.  if i knew perl i'd love to get it all into one script... oh well.

/edt: came up with a way simpler way to do it

Last edited by brisbin33 (2009-08-12 20:23:52)

Offline

#462 2009-08-12 16:40:26

tch
Member
From: Slovakia
Registered: 2007-10-07
Posts: 31

Re: Post your handy self made command line utilities

A script for easy note-taking. Can be used directly from the terminal or if you use Xmonad you can do it more elegantly. ;)

#!/bin/sh

# Starting position of text
Y=60
X=60
# Distance between lines
YSPACE=30
# Temp file containing the message count
MFILE=/home/tch/.note
# Initial wallpaper
FILE=/home/tch/wallpapers/`date +'%m'`.jpg
# Temporary file
TMPFILE=/home/tch/wallpapers/tmp.jpg
# Font and color
FONT="-xos4-terminus-bold-*-*-*-32-*-*-*-*-*-*-*"
COLOR="#c2c2c2"

if [ -f $MFILE ]; then
    FILE=$TMPFILE
    C=`cat $MFILE`
else
    C=1
    echo 1 > $MFILE
fi

Y=$(($Y + ($YSPACE * ($C - 1))))

convert -font $FONT -fill $COLOR -draw "text $X,$Y '$*'" $FILE $TMPFILE
feh --bg-center $TMPFILE
echo $(($C+1)) > $MFILE

tMjUzZA tMjUzZg tMjUzOQ

xmonad.hs usage with shellPrompt ( first picture )

import XMonad
import XMonad.Operations
import XMonad.Actions.DwmPromote
import XMonad.Hooks.DynamicLog   ( PP(..), dynamicLogWithPP, dzenColor, wrap, defaultPP )
import XMonad.Layout
import XMonad.Layout.NoBorders
import XMonad.Prompt             ( XPConfig(..), XPPosition(..) )
import XMonad.Prompt.Shell       ( shellPrompt )
import XMonad.Prompt.Man
import XMonad.Util.Run
import XMonad.Hooks.ManageDocks
 
import qualified Data.Map as M
import Data.Bits ((.|.))
import Data.Ratio
import Graphics.X11                                                                                                    
import System.IO
 
statusBarCmd= "/usr/local/bin/dzen2 -bg '#000000' -fg '#0000ff' -w 1080 -sa c -e '' -ta l -fn '-*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*'"
 
main = do din <- spawnPipe statusBarCmd
          xmonad $ defaultConfig
                     { borderWidth        = 0
                     , workspaces         = [".", ":", ".:", "::", ":.:", ":::"] 
                     , terminal           = "urxvt"
                     , modMask            = mod4Mask
                     , manageHook         = manageDocks
                     , logHook            = dynamicLogWithPP $ robPP din
                     , layoutHook         = avoidStruts (Mirror tiled ||| tiled ||| noBorders Full)
                     , keys               = \c -> robKeys `M.union` 
                                                  keys defaultConfig c 
                     }
                     where
                       tiled = Tall 1 (3%100) (1%2)
 
defaultGaps' :: [(Int,Int,Int,Int)]
defaultGaps' = [(12,0,0,0), (12,0,0,0)] -- 15 for default dzen font
 
-- redifine some keys
--

robSPConfig = XPC { 
             font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"
                         , bgColor           = "#111111"
                         , defaultText         = "note "
                 , fgColor           = "#d5d3a7"
                 , bgHLight          = "#aecf96"
                 , fgHLight          = "black"
                 , borderColor       = "black"
                         , promptBorderWidth = 0
                 , position          = Bottom
                         , height            = 15
                         , historySize       = 256
             , autoComplete         = Nothing
                   }

robKeys = M.fromList $
   [ 
    ((mod4Mask, xK_Return), dwmpromote)
    ,((mod4Mask, xK_b), sendMessage ToggleStruts) 
    ,((mod4Mask, xK_n), shellPrompt robSPConfig)
    ,((mod4Mask, xK_m), spawn "clearnote")
    ,((mod4Mask, xK_Print), spawn "import -window root /home/tch/shots/shot.png; mv /home/tch/shots/shot.png /home/tch/shots/`date +'%Y%m%d-%H%M%S'`.png")
   ]
 
 
-- dynamiclog pretty printer for dzen
--
robPP h = defaultPP 
                 { ppCurrent = wrap "^fg(#000000)^bg(#0000ff)^p(2)" "^p(2)^fg()^bg()"
                  , ppSep     = " | "
                  , ppLayout  = dzenColor "#80AA83" "" .
                                (\x -> case x of
                                         "Tall" -> "T"
                                         "Mirror Tall" -> "M"
                                         "Full" -> "F"
                                )
                  , ppTitle   = wrap "[ " " ]" 
                  , ppOutput   = hPutStrLn h
                  }

And the clearnote script

#!/bin/sh

feh --bg-center /home/tch/wallpapers/`date +'%m'`.jpg
rm /home/tch/.note

Offline

#463 2009-08-13 23:35:54

Themaister
Member
From: Horten, Norway
Registered: 2008-07-21
Posts: 647
Website

Re: Post your handy self made command line utilities

Having a wallpaper folder where the script picks wallpapers at random smile Very handy if you like OpenBox and change your wallpaper often.

#!/bin/bash

DIR="/home/maister/Pictures/Wallpaper"
INTERVAL="10m"

while true
do
        RANGE=`ls "$DIR" | wc -l`
        echo "RANGE is $RANGE"
        NUMBER=$RANDOM
        let "NUMBER %= $RANGE"
        let "NUMBER += 1"
        WALLPAPER=`ls "$DIR" | head -n $NUMBER | tail -n 1`     
        feh --bg-scale "$DIR"/"$WALLPAPER"
        echo $WALLPAPER
        echo "Picked number $NUMBER"
        sleep "$INTERVAL"
done

Offline

#464 2009-08-13 23:51:49

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Post your handy self made command line utilities

Script to pick a random wallpaper when run. I run it from my .xinitrc smile

#!/bin/bash

papers=/usr/share/wallpapers/rotation/

background="$papers`ls $papers -c1 | sort -R | head -n1`"
feh --bg-scale "$background"

Offline

#465 2009-08-14 06:30:41

Themaister
Member
From: Horten, Norway
Registered: 2008-07-21
Posts: 647
Website

Re: Post your handy self made command line utilities

Rofl. sort -R basically made my whole "pick random wallpaper" script feel retarded. XD I learn something every day.

Offline

#466 2009-08-14 08:14:51

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,716

Re: Post your handy self made command line utilities

Or, even shorter, use shuf  wink

Last edited by lolilolicon (2009-08-14 08:15:18)


This silver ladybug at line 28...

Offline

#467 2009-08-14 10:19:45

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Offline

#468 2009-08-14 12:08:03

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Post your handy self made command line utilities

lnk

Because I can't always remember the order of how to do links (what comes first) I created this script to: display usage, check if the name matches, and display the link to be sure I got it right.

#!/bin/bash
# lnk - link files/folders without broken links and feedback
# Author: Gen2ly

# Text color variables
TXTBLD=$(tput bold)     # Bold
TXTUND=$(tput sgr 0 1)  # Underline
TXTRED=$(tput setaf 1)  # Red
TXTGRN=$(tput setaf 2)  # Green
TXTYLW=$(tput setaf 3)  # Yellow
TXTBLU=$(tput setaf 4)  # Blue
TXTPUR=$(tput setaf 5)  # Purple
TXTCYN=$(tput setaf 6)  # Cyan
TXTWHT=$(tput setaf 7)  # White
TXTRST=$(tput sgr0)     # Reset

# Display usage if full argument if isn't given.
if [[ -z "$2" ]]; then
  echo " lnk <file-or-folder> <link-to-location>"
  exit
fi

# Check if file or folder exists
if [[ ! -f $1 ]] && [[ ! -d $1 ]]; then
  echo " File/folder does not exist"
  exit
fi

# Variables to check if link points to a folder or to a new link
LINKDIR=${2%/}/${1##*/}
LINKNEW=$2

# Check if the link name matches another link
if [[ -L $LINKDIR ]] || [[ -L $LINKNEW ]]; then
  echo " Link already exists:"
  if [[ -L $LINKDIR ]]; then
    echo " $(ls -la --color=always $LINKDIR | awk '{printf $8" "$9" "$10}')"
  fi
  if [[ -L $LINKNEW ]]; then
    echo " $(ls -la --color=always $LINKNEW | awk '{printf $8" "$9" "$10}')"
  fi
  exit
fi

# Check if link name matches a file name
if [[ -f $LINKDIR ]] || [[ -f $LINKNEW ]]; then
    echo " File already exists with that name:"
  if [[ -f $LINKDIR ]]; then
    echo " $(ls -la --color=always $LINKDIR | awk '{printf $1" "$8}')"
  fi
  if [[ -f $LINKNEW ]]; then
    echo " $(ls -la --color=always $LINKNEW | awk '{printf $1" "$8}')"
  fi
  exit
fi

# Create symbolic link
#'ln' needs path argument for linking a file in the current directory
# realpath extracts '\'s before spaces
FPATH=`realpath "$1" | sed -e 's: :\\ :g'`
ln -s "$FPATH" $2

# Display colors for full file path, link same path, link new path
FPATHDIS=${TXTBLD}${TXTGRN}$FPATH${TXTRST}
LINKDIRDIS="${TXTBLD}${TXTCYN}$(realpath -s "$LINKDIR")${TXTRST}"
LINKNEWDIS="${TXTBLD}${TXTCYN}$(realpath -s $LINKNEW)${TXTRST}"

# Display linked file
if [[ -L $LINKDIR ]]; then
  echo " $FPATHDIS -> $LINKDIRDIS"
fi

if [[ -L $LINKNEW ]]; then
  echo " $FPATHDIS -> $LINKNEWDIS"
fi

# Limitations
# Because lnk must check if the link points to a folder or a new linkname,
# if creating a link that has the same name as a directory and the link has 
# the same name as a link in that directory, lnk will fail from a link check.

Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#469 2009-08-14 12:40:51

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Post your handy self made command line utilities

Simple commandline mpd-client

#!/bin/bash

HOST=localhost
PORT=6600

typeset -A status

Command() {
    [ ! -t 3 ] && exec 3<>/dev/tcp/${HOST}/${PORT} 
    echo $@ >&3 
}

GetStatus() {
    Command $1
    while read line; do 
        case ${line} in 
            OK) break;;
            *) status[${line/:*/}]=${line/*: /};;
        esac
    done <&3
}

SongInfo() {
    GetStatus currentsong
    currentsong="${status[Artist]} - ${status[Title]}"
    [ "${currentsong}" != "${oldsong}" ] && echo ${currentsong} && oldsong=${currentsong}
}

Toggle() {
    GetStatus status
    [ "${status[state]}" ==  "stop" ] || [ "${status[state]}" == "pause"  ] && Command play || Command pause 
}

ToggleStatus() {
    GetStatus status
    [ "${status[$1]}" -eq  0 ] && (echo "$1: on" &&  Command $1 1) || (echo "$1: off" && Command $1 0)
}

Interactive() {
while :; do
    while read -n 1 -s -t 1 line; do
        case ${line} in 
            p) Command play;;
            s) Command stop;;
            P) Command pause;; 
            n) Command next;; 
            t) Toggle;;
            z) ToggleStatus random;;
            r) ToggleStatus repeat;;
            b) Command previous;;
            q) exit 0;; 
        esac
    done
    SongInfo
done
}
[ "$#" -gt 1 ] && exit 1
case $1 in 
    -p|play) Command play;; 
    -P|pause) Command pause;;
    -s|stop) Command stop;;
    -n|next) Command next;;
    -b|prev) Command previous;;
    -t|toggle) Toggle;;
    -r|repeat) ToggleStatus random;;
    -z|random) ToggleStatus repeat;;
    -i|interactive) Interactive;;
    *) SongInfo && exit 0;;
esac
SongInfo

Offline

#470 2009-08-14 12:45:12

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Why not use mpc?

Offline

#471 2009-08-14 12:46:48

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Post your handy self made command line utilities

I was just bored

Offline

#472 2009-08-14 15:26:50

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: Post your handy self made command line utilities

Ugly as crap, and possibly not the best way to do it, but it gives me the output of iwlist scan as quality - essid - encryption status.
I know, I know, I could install a proper wireless manager too but ...meh

#!/bin/sh
iwlist wlan0 scanning|egrep "Quality|ESSID|Encryption"|sed "N;N;s/.*Quality=\\([0-9/]*\\).*\n.*\\(Encryption key:[a-z]\\{2,3\\}\\).*\n.*ESSID:\\(\".*\"\\)/\\1 - \\3 - \\2/"|sort -gr

I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

#473 2009-08-15 11:17:32

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Post your handy self made command line utilities

Define a word using the dict.org server.

function define ()
{
    dictionary="english"
    [[ "$2" != "" ]] && dictionary=$2
    echo "DEFINE $dictionary $1\nQUIT" | netcat dict.org 2628
}

Offline

#474 2009-08-15 13:43:51

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Post your handy self made command line utilities

Small improvement to my pkill frontend, now it is more appropriate for killing multiple processes and the interface is simpler. Send SIGKILL by trying to send SIGTERM for the second time.

#! /bin/bash
IFS="
"
hist=0
while true; do
processes=$(ps -o pid,cmd,etime,time,pcpu,pmem,ppid,euser -p $(pgrep "$1") 2>/dev/null) || exit
echo "   "$(echo "$processes" | head -n 1)
processes=$(echo "$processes" | tail -n +2)
    select process in $processes; do
    pid=$(echo $process | sed 's/^ *\([0-9]*\).*$/\1/')
    [ -z "$pid" ] && exit
    if echo "$hist" | grep -qx $pid; then
        echo SIGKILL $pid
        kill -9 $pid
    else
        echo SIGTERM $pid
        kill $pid
    fi
    hist=$hist$'\n'$pid
    break
    done
done

edit: added -x for grep

Last edited by Procyon (2009-08-15 13:50:04)

Offline

#475 2009-08-15 19:17:10

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Post your handy self made command line utilities

Barrucadu wrote:

Define a word using the dict.org server.

function define ()
{
    dictionary="english"
    [[ "$2" != "" ]] && dictionary=$2
    echo "DEFINE $dictionary $1\nQUIT" | netcat dict.org 2628
}

I have a script that does the same with googles define feature

dictionary(){ 
echo Definitions of  $1 on the Web:
echo " "
curl -s -A 'Mozilla/4.0'  'http://www.google.co.uk/search?q=define%3A+'$1  | html2text -ascii -nobs -style compact -width 500 | grep "*" | head -n 5
}

Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

Board footer

Powered by FluxBB