You are not logged in.

#701 2009-12-02 11:35:41

MrBlueSky
Member
From: Florida
Registered: 2009-11-19
Posts: 11
Website

Re: Post your handy self made command line utilities

Randomly colored urxvt terminal window:

#!/usr/bin/ python

import sys, os, random

r = random.randint(1000,8888)
g = random.randint(1000,8888)
b = random.randint(1000,8888)

os.system("urxvt -depth 32 -bg rgba:" + str(r) + "/" + str(g) + "/" + str(b) + "/0000")

Offline

#702 2009-12-02 17:07:12

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: Post your handy self made command line utilities

presario wrote:

Not really a utility but a trick that I often use when I'm too lazy to write a (bash) script:

a_very_very_long_and_complex_command #tag

After that I can retrieve the command by typing:

^R#tag

The point is about labeling commands for easy retrieval so that you don't have to recall parts of the command that uniquely identify it.

That's a nice one!

I use this a lot

$ cat .inputrc
"\e[A":history-search-backward
"\e[B":history-search-forward

up and down keys scroll the history. Easy to find screen -raAd from history. $ sc(uparrow once or twice)

Offline

#703 2009-12-02 19:54:11

toorlv
Member
Registered: 2009-11-01
Posts: 65

Re: Post your handy self made command line utilities

karabaja4 wrote:
Daenyth wrote:
karabaja4 wrote:

for atheros wireless cards - script to download & install newest madwifi revision from 0.9.4.1 branch (trunk revisions are somewhat slow for me).

http://karabaja.pondi.hr/scripts/update2.sh

Why not use the madwifi-svn package?

Well look at that big_smile

didn't know it was there. Anyway, its madwifi-hal-testing branch, I have no idea how it performs against 0.9.4.1 (btw 0.9.4.1 out-performs trunk by alot, why is this?). Will test and report back.

P.S. I'm also kinda more at peace with "make && make install" method smile

EDIT: It performs exacly the same... interesting ^^

---

Sorry for offtopic, but can you share your bashrc?

Offline

#704 2009-12-02 20:18:07

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

Re: Post your handy self made command line utilities

Who exactly? Mine is in my sig.

Offline

#705 2009-12-03 00:42:13

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,001
Website

Re: Post your handy self made command line utilities

toorlv wrote:

Sorry for offtopic, but can you share your bashrc?

Mine? I have almost none:

# Check for an interactive session
[ -z "$PS1" ] && return

alias ls='ls --color=auto'
PS1='[deadbeef \W]\$ '

P.S. Ehm, really, I must ask, why you want to have every single config exacly like me? There isn't a config file you didn't ask me to upload lol. Not that I mind sharing, but you should really try to make your own configuration that you like best and that best suits your needs and habits.

Offline

#706 2009-12-04 11:56:14

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: Post your handy self made command line utilities

I use this to quickly scan my syslogs for errors. Kinda crude but it works.  It searches for lines with todays date, except for Xorg.0.log which has no date field.

export LC_TIME="POSIX"
sudo  egrep -ri "$(date '+%b %e')"'.*(missing|error|fail|(no |not |in)valid|fatal|corrupt|warning|wrong|illegal| fault|caused)' /var/log/*  | sort -u
sudo  egrep -iH '(missing|error|fail|(no |not |in)valid|fatal|corrupt|warning|wrong|illegal| fault|caused|\(EE\)|\(WW\))' /var/log/Xorg.0.log  | sort -u

B.t.w. How about putting up some kind of vote for the best scripts in this thread, maybe per category (files, networking, general ..)?

Last edited by rwd (2009-12-04 15:35:46)

Offline

#707 2009-12-04 16:05:29

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

Who needs AutoFS? Background this!

inotifywait -qm --event CREATE --format %f /dev | while read disk; do
    if [[ -b /dev/$disk ]] && [[ ${disk:0:2} == 'sd' ]] && [[ ${disk:(-1)} == [[:digit:]] ]]; then
        sleep 1
        devkit-disks --mount /dev/$disk
    fi
done

Offline

#708 2009-12-04 16:14:32

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

Re: Post your handy self made command line utilities

note: a uzbl-script

this'll take you back to the most recent and different domain.  let me explain.

say you google something, follow a link, navigate about that site for 12 or so pages, then you want to go back to the google results directly... bind this script to gb.

or let's say you click a screenshot link out of bbs.archlinux.org, navigate about deviantart for 10 or so pages, then you want to go back to the forums... that keybind will take you back to the most recent history entry for bbs.archlinux.org i.e. that forum post that you originally navigated away from.

i find it comes in handy.

#!/bin/bash
#
# pbrisbin 2009
#
###

uzbl_sok="$5" # our socket
curr_url="$6" # our url

history_file="$XDG_DATA_HOME/uzbl/history" # our history file

[ ! -f "$history_file" ] && exit 1

# print the history file in reverse, strip to just urls
tac "$history_file" | awk '{print $3}' | while read this_url; do
  # strip to just the domain
  curr_domain=$(echo $curr_url | cut -d '/' -f 3)
  this_domain=$(echo $this_url | cut -d '/' -f 3)

  # find the next entry from a different domain
  if [ "$this_domain" != "$curr_domain" ]; then
    echo uri $this_url | socat - unix-connect:$uzbl_sok &
    break
  fi
done

Last edited by brisbin33 (2009-12-04 16:16:25)

Offline

#709 2009-12-04 17:39:34

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Post your handy self made command line utilities

falconindy wrote:

Who needs AutoFS? Background this!

Great! I was looking for something like this to do automounting in WindowMaker. I'll put the code in a file called "simple-automount" and start it at boot. Then I'll add a "live" item to the WindowMaker root menu to show me the contents of "/media". big_smile

By the way, how do you handle unmounting? tongue

Offline

#710 2009-12-04 18:29:16

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

drcouzelis wrote:
falconindy wrote:

Who needs AutoFS? Background this!

Great! I was looking for something like this to do automounting in WindowMaker. I'll put the code in a file called "simple-automount" and start it at boot. Then I'll add a "live" item to the WindowMaker root menu to show me the contents of "/media". big_smile

By the way, how do you handle unmounting? tongue

I should really make some aliases this handle this. For now its either 'sudo umount /dev/wutev' or 'devkit-disks --unmount /dev/yada/yada/why/am/i/still/typing'

I don't mind the fact that this ignores my DVD drive because its not hard to type `mount /dev/dvd`.

edit: dont start it at boot. there's some finicky business about when this will and won't work. my testing shows:
from a tty: fail
from screen: fail
from xinitrc: fail
from a straight terminal session: win!

Which means that it needs to be started manually. I wonder if I can source the .Xauth file and do it that way.... hmmmmm....

Last edited by falconindy (2009-12-04 18:43:23)

Offline

#711 2009-12-04 19:35:06

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

Re: Post your handy self made command line utilities

Maybe there's some dbus session related issue from starting it early?

Offline

#712 2009-12-04 19:37:44

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

Re: Post your handy self made command line utilities

i'd try from rc.local:

( sleep 30 && su -c 'bash -cl \'command_to_start_as_me_in_a_login_shell\'' username ) &

note: wholely untested and will likely need tweaking... but you get the idea.

Offline

#713 2009-12-04 21:09:47

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Post your handy self made command line utilities

#!/bin/bash
echo $$ > ~/Tmp/alarm
amixer set Master 23 > /dev/null
amixer set PCM 0 > /dev/null
mocp -U
x=0
y=0
while [ $x -le 5 ]
do
x=$(( $x + 1 ))
y=$(( $y + 30 ))
amixer set PCM $(($x * 2)) > /dev/null
beep -f $((360+$y))
echo $(( $y + 360 ))'Hz'
sleep 10s
y=$(( $y + 30 ))
beep -f $((360+$y))
sleep 10s
done
date
~/Code/bash/beep

Code/bash/beep:

!/bin/bash
echo $$ > Tmp/alarm
while [ 1 ]
do
x=$[ ( $RANDOM % 4900 + 100 ) ]
echo -n $x','
beep -f $x &
sleep 0.2s
done

does get you up in the morning, especially if you put the keyboard downstairs wink

Offline

#714 2009-12-05 04:01:49

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

Re: Post your handy self made command line utilities

Not so much a "utility", but when using vim to edit PKGBUILD files, this will get rid of the old startdir/ junk

:%s/startdir\/\(pkg\|src\)/\1dir/g

Offline

#715 2009-12-05 16:23:31

spupy
Member
Registered: 2009-08-12
Posts: 218

Re: Post your handy self made command line utilities

markp1989 wrote:

here is a simple application launcher i wrote a while ago, it was inspired by a screen manager that i found in this thread a while ago.

In relation to zenity and launchers - I was disappointed that zenity didn't have the ability to create pop-up menus. I did like to use the list form for launching stuff. For this reason I created this script:
http://pastebin.com/f6ec7eb1a
Called like this:

python PyMenu.py browser:firefox editor:gedit:gtk-edit "file manager":nautilus:gtk-harddisk

it opens a pop-up menu under the mouse. The format is label:command[:gtk_stock_id]

EDIT: Of course requires python and pygtk.

Last edited by spupy (2009-12-05 17:11:55)


There are two types of people in this world - those who can count to 10 by using their fingers, and those who can count to 1023.

Offline

#716 2009-12-06 06:55:33

vik_k
Member
From: Pune, India
Registered: 2009-07-12
Posts: 227
Website

Re: Post your handy self made command line utilities

just a small code for getting no. of files & directories in a directory using tree.
might be available with another piece of code but i was unable to find it.

files() {
  if [ ! -z "$1" ]; then
    echo "==> $(tree "$1" &> /dev/null | tail -1) [$(du -hs "$1" | cut -f1)]"
  else
    echo "==> $(tree "$(pwd)" &> /dev/null | tail -1) [$(du -hs "$(pwd)" | cut -f1)]"
  fi
}

i use it as a function

Last edited by vik_k (2009-12-06 06:56:47)


"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack." ~ George Carrette

Offline

#717 2009-12-06 07:13:01

GraveyardPC
Member
Registered: 2008-11-29
Posts: 99

Re: Post your handy self made command line utilities

vik_k wrote:

just a small code for getting no. of files & directories in a directory using tree.
might be available with another piece of code but i was unable to find it.

files() {
  if [ ! -z "$1" ]; then
    echo "==> $(tree "$1" &> /dev/null | tail -1) [$(du -hs "$1" | cut -f1)]"
  else
    echo "==> $(tree "$(pwd)" &> /dev/null | tail -1) [$(du -hs "$(pwd)" | cut -f1)]"
  fi
}

i use it as a function

Wouldn't it be easier to just use:

files(){ set ${1:-$PWD}; echo "==> $(tree "$1" | tail -1) [$(du -hs "$1" | cut -f1)]"; }

EDIT: I just stole this for my bashrc, regardless. tongue

Last edited by GraveyardPC (2009-12-06 07:51:55)

Offline

#718 2009-12-06 08:03:51

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: Post your handy self made command line utilities

Stuff from my .zsh_functions, sourced by .zshrc:

md5name()
{
    if [[ -f $1 ]]; then
        while [[ -f $1 ]]; do
            mv $1 ${$(md5sum $1)[1]}.${1##*.}
            shift
        done
    else
        echo "$0: Provide at least one input file, you lemonade head."
    fi
}
fiximageexts()
{
    zmv '(*).(#i)(jpeg|jpg)' '$1.jpg'
    zmv '(*).(#i)(gif)' '$1.gif'
    zmv '(*).(#i)(png)' '$1.png'
    zmv '(*).(#i)(bmp)' '$1.bmp'
}
mktar7z()
{
    echo "Encrypt?"
    read enc
    tar cf - $argv[2,-1] | 7z a -si $1 `[[ ! -z $enc ]] && echo "-p$enc"`
}
getip()
{
    curl http://whatismyip.org/ 2>/dev/null|xclip -i
}

Last edited by JohannesSM64 (2009-12-06 08:07:01)

Offline

#719 2009-12-06 08:13:49

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

Re: Post your handy self made command line utilities

Your have() is useless...
Either write
have() { for i in "$@"; do type "$i" &>/dev/null || return 1; done; }
or simpler
have() { type "$@" &>/dev/null ; }
If or you want is ``true if and only if I have them ALL''

Edit: Found you edited it. nvm then.

Last edited by lolilolicon (2009-12-06 08:16:11)


This silver ladybug at line 28...

Offline

#720 2009-12-06 09:18:38

vik_k
Member
From: Pune, India
Registered: 2009-07-12
Posts: 227
Website

Re: Post your handy self made command line utilities

GraveyardPC wrote:

Wouldn't it be easier to just use:

files(){ set ${1:-$PWD}; echo "==> $(tree "$1" | tail -1) [$(du -hs "$1" | cut -f1)]"; }

EDIT: I just stole this for my bashrc, regardless. tongue

got it!!! big_smile


"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack." ~ George Carrette

Offline

#721 2009-12-06 18:01:12

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: Post your handy self made command line utilities

<removed>

Last edited by rwd (2009-12-06 18:08:37)

Offline

#722 2009-12-06 20:59:52

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

Re: Post your handy self made command line utilities

threw this together last night while trying to get my various contact lists in order.

#!/bin/bash

IN='./vcard.vcf'
OUT='./mutt_alias_file'

awk -F ':' '/^FN:|^EMAIL/ {print $2}' "$IN" | while read entry; do
  this="$entry"
  
  # if this entry is an email and the last entry was not, then it's our
  # primary email so print it.
  if [ "$this" != "${this//@/}" -a "$last" = "${last//@/}" ]; then
    echo "alias ${last// /_} $last <$this>" >> "$OUT"
  fi

  last="$entry"
done

Offline

#723 2009-12-06 22:36:58

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

Wrote this because I didn't find it in pkgtools. Prints files owned by a package:

#!/bin/bash

PACDB="/var/lib/pacman/local"

[[ -z $1 ]] && "Need a valid package to query" && exit 1

multifound() {
        echo -e "${#pkgs[*]} packages found:\n"
        for pkg in ${pkgs[*]}; do
                printf "  %s\n" $pkg
        done
        echo -e "\nPlease refine your search."
        exit 0
}

listfiles() {
        sed -n -e '/%FILES%/,/^$/p' $PACDB/$1-*/files | less
        exit 0
}

pkgs=($(pacman -Qs $1 | grep -e ^local | cut -d\/ -f2 | cut -d\  -f1))

[[ $pkgs = $1 ]] && listfiles $1

case ${#pkgs[*]} in
        0) echo "No package '$1' found" ;;
        1) listfiles $1 ;;
        *) multifound ;;
esac

Could likely be cleaner, but it works (so far). Pretty sure the check for an exact match is a filthy hack.

edit: fix pkg searching

Last edited by falconindy (2009-12-06 22:59:13)

Offline

#724 2009-12-06 23:16:19

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

Re: Post your handy self made command line utilities

falconindy wrote:

Wrote this because I didn't find it in pkgtools. Prints files owned by a package:

`pkgfile -l`? You can also file feature requests if there's something you want pkgtools to do that it doesn't

Offline

#725 2009-12-06 23:25:11

GGLucas
Member
Registered: 2008-03-13
Posts: 113

Re: Post your handy self made command line utilities

What's wrong with "pacman -Ql"?

Offline

Board footer

Powered by FluxBB