You are not logged in.

#876 2010-03-02 00:03:48

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 876
Website

Re: Post your handy self made command line utilities

I do it like this:

find . -iname '*.rar' -execdir rar x {} $(pwd | perl -pe 's/^((?:\/[^\/]+){2}\/).*/$1/').temp/ \;
mplayer $(pwd | perl -pe 's/^((?:\/[^\/]+){2}\/).*/$1/').temp/* && rm $(pwd | perl -pe 's/^((?:\/[^\/]+){2}\/).*/$1/').temp/*
#echo $(basename $(pwd)) >> /mnt/Movies_1/.seen

Offline

#877 2010-03-02 04:48:09

supulton
Member
Registered: 2008-12-31
Posts: 58

Re: Post your handy self made command line utilities

here's an alarm script working through gxmessage and mpd (and mpc). it seems to be working fine, but ive only been using it a few days. create an "alarm" playlist, set time between snoozes, and set a cronjob like so:

00 5 * * 1-5 export DISPLAY=:0.0 && sh /home/vic/scripts/wakethehellup.sh
#!/bin/bash
# wakethehellup.sh

# amount of time between snoozes in minutes 
ztime=60

# load playlist
mpc -q clear; mpc load alarm; mpc -q shuffle

# set volume to loud, play
vol=$1; mpc -q volume ${vol:-70}; mpc play

# gxmessage alarm
alarm_message() {
gxmessage -center \
    -buttons "Stop":1,"Snooze":2 \
    -geometry 400x80 \
    -title "Alarm" \
    'Get up for school ya lazy bum!'    
    action=$?
}

# snooze or stop?
export DISPLAY=:0.0
alarm_message
while [ $action -ne 1 ]
do
    if [ $action -eq 2 ] ;then
        mpc -q pause
        sleep 3; xset dpms force standby
        sleep "$ztime"m
        xset dpms force on
        sleep 3; mpc play
    fi
    alarm_message
done
mpc -q stop

link: http://github.com/supulton/gitstuff/blo … ehellup.sh

Offline

#878 2010-03-02 06:48:51

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 876
Website

Re: Post your handy self made command line utilities

Simple calculator. Could be used as interactive perl interpreter too, ofc.

#!/usr/bin/perl
while(<>){die if/:q/;print'='.eval,"\n"}

-4+5
=1
printf("%10s %15s\n", 'Arch', 'Linux');
      Arch           Linux

pwc. Simple weather fetcher. IRC format supported. List of towns to lookup supported.

#!/usr/bin/perl 
#pwc
use strict;
use warnings;
use Getopt::Long;
use Weather::Google;

our $irc;
GetOptions(
  'irc'   => \$irc,
);

my @towns = @ARGV;

if(!@ARGV) {
  print "Specify town(s).\n";
}

# In case we need more then one 
my @gobjects;

my %data;
foreach my $town(@towns) {
  push @{$data{$town}}, Weather::Google->new($town)->current(
                                                             'temp_c',
                                                             'condition',
                                                             'humidity',
                                                             'wind_condition',
                                                             );
}
my $town;
my @data;
foreach $town(sort keys %data) {
  @data = @{$data{$town}};
  foreach my $line (@data) {
      if(!defined($line)) {
          $line = "undef";
      }
  }
  # I'm lazy
  if(!$irc) {
      print "\033[31;1m",ucfirst($town),"\033[0m\n";
      print "Celsius: $data[0]°C\n";
      print "Condition: $data[1]\n";
      print "$data[2]\n";
      print "$data[3]\n";
  }
  else {
      # skummeslövsstrand
      # The idea was to use %${lenght}s, but if that should work I'll have to
      # figure out the longest string in @ARGV, which is simple, but I doubt
      # that I'll get the formatting good anyway - therefore I leave it like
      # this for now.
      printf("%0s %0s %0s %0s %0s\n", '·',ucfirst($town).':', "$data[0]°C",
             "[$data[1]]","| $data[3]");
  }
}

» pwc washington
Washington
Celsius: 4°C
Condition: Cloudy
Humidity: 61%
Wind: NW at 13 mph
__________________
» pwc washington cairo stockholm oslo helsinki -i
· Cairo: 17°C [Haze] | Wind: SW at 8 mph
· Helsinki: 0°C [Light snow] | Wind: N at 2 mph
· Oslo: -8°C [Clear] | Wind: N at 2 mph
· Stockholm: -8°C [Mostly Cloudy] | Wind: W at 15 mph
· Washington: 4°C [Cloudy] | Wind: NW at 13 mph

wink

#!/usr/bin/perl
$c='python';$_=`printf hack`;$_=~s;ck;;;;$c=~s%^(?!\x68)(.)(?2)(?1)(.)(?1)(?2)(?<!.{4}h)$%$2%;print j.substr($_,1),p,$c.",\n"

Offline

#879 2010-03-04 01:17:17

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

Re: Post your handy self made command line utilities

A few pacman scripts.  I've showed these before but I've simplified them and cleaned them up a bit.

pacbac - creates backup list of installed packages.  Creates separate lists for Official repositories and a Local repository (usually the AUR packages for me).

#!/bin/bash
# pacbac - Create Official and Local lists of installed packages

# Package list locations (official and local)
pkglsdir=/home/todd/.bin/root/backup
pkglsoff="$pkglsdir"/pkglist-off.txt
pkglsloc="$pkglsdir"/pkglist-loc.txt

# Use filename as program name
prog=${0##*/}

# Text color variables
if [ $(whoami) != "cron" ]; then
txtund=$(tput sgr 0 1)          # Underline
txtcyn=$(tput setaf 6)          # Cyan
txtbld=$(tput bold)             # Bold
bldred=${txtbld}$(tput setaf 1) #  red
bldblu=${txtbld}$(tput setaf 4) #  blue
bldwht=${txtbld}$(tput setaf 7) #  white
txtrst=$(tput sgr0)             # Reset
info=${bldwht}*${txtrst}        # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}
fi

# Check that backup folder exists
if [ ! -d "$pkglsdir" ]; then
  echo "$warn Package list directory doesn't exist: ("$pkglsdir")"
  echo "$info Exiting"
  exit
fi

# Continue?
echo -n "Create list of official, and list of local packages? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read listcreate

# Create lists
if [ $listcreate = "y" ]; then
  # Create full list, remove local, base
  echo "$info Creating list of official (core/extra/community packages) packages installed."
  pacman -Qqe | grep -vx "$(pacman -Qqg base)" | grep -vx "$(pacman -Qqm)" > "$pkglsoff"
  # Create list of local packages (includes the AUR)
  echo "$info Creating list of local (includes AUR) packages installed."
  pacman -Qqm > "$pkglsloc"
  # Information
  echo "$pass Official package list created: ${txtund}"$pkglsoff"${txtrst}"
  echo "$pass Local package list created: ${txtund}"$pkglsloc"${txtrst}"
fi

pacrest - installs packages from package list created with pacbac (useful for reinstalling):

#!/bin/bash
# pacrest - Restore from list Official and Local packages

# Package list locations (official and local)
pkglsdir=/home/todd/.bin/root/backup
pkglsoff="$pkglsdir"/pkglist-off.txt
pkglsloc="$pkglsdir"/pkglist-loc.txt

# Use filename as program name
prog=${0##*/}

# Text color variables
if [ $(whoami) != "cron" ]; then
txtund=$(tput sgr 0 1)          # Underline
txtcyn=$(tput setaf 6)          # Cyan
txtbld=$(tput bold)             # Bold
bldred=${txtbld}$(tput setaf 1) #  red
bldblu=${txtbld}$(tput setaf 4) #  blue
bldwht=${txtbld}$(tput setaf 7) #  white
txtrst=$(tput sgr0)             # Reset
info=${bldwht}*${txtrst}        # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}*${txtrst}
fi

# Check that the package list folder exists
if [ ! -d "$pkglsdir" ]; then
  echo "$warn Package list directory doesn't exist: ("$pkglsdir")"
  echo "$info Exiting"
  exit
fi

# Check that a package list exists
if [ ! -f "$pkglsoff" ] && [ ! -f "$pkglsloc" ]; then
  echo "$warn No package lists exist:"
  echo "$warn $pkglsoff and $pkglsoff"
  echo "$info Exiting"
  exit
fi

# Be sure yaourt is installed
if [[ ! -f /usr/bin/yaourt ]]; then
  echo
  echo "$warn $prog requires ${txtund}}Yaourt${txtrst} to be installed."
  echo "  ${txtcyn}http://wiki.archlinux.org/index.php/Yaourt${txtrst}"
  echo
  exit
fi

# Restore Official or Local?
echo -n "Do you want to restore Official or Local packages? (${txtbld}o${txtrst}/${txtbld}l${txtrst}): "
read restore

if [ $restore = "o" ]; then
  sudo pacman -Sy
  sudo pacman -S --needed $(cat "$pkglsoff")
fi

if [ $restore = "l" ]; then
  yaourt -S $(cat "$pkglsloc" | grep -vx "$(pacman -Qqm)")
fi

pacrein - Re-installs all packages (installs explicit a explicit and dependencies as dependencies).  Not often a use for this script but nice to have around:

#!/bin/bash
# pacrein - Re-install all Official and Local packages

# Local package cache
locpkgcache=/var/cache/pacman-local/pkg

# Use filename as program name
prog=${0##*/}

# Text color variables
if [ $(whoami) != "cron" ]; then
txtund=$(tput sgr 0 1)          # Underline
txtcyn=$(tput setaf 6)          # Cyan
txtbld=$(tput bold)             # Bold
bldred=${txtbld}$(tput setaf 1) #  red
bldblu=${txtbld}$(tput setaf 4) #  blue
bldwht=${txtbld}$(tput setaf 7) #  white
txtrst=$(tput sgr0)             # Reset
info=${bldwht}*${txtrst}        # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}
fi

# If rebuilding, be sure yaourt is installed
if [[ "$1" == 'r' ]] && [[ -z $(pacman -Qs yaourt) ]]; then
    echo
    echo "$warn $prog requires ${txtund}}Yaourt${txtrst} to be installed."
    echo "  ${txtcyn}http://wiki.archlinux.org/index.php/Yaourt${txtrst}"
    echo
    exit
fi

# Sync db, download only
echo -n "Upgrade database, and download new packages? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read updbdown

if [ $updbdown = "y" ]; then
  sudo pacman -Sy
  sudo pacman --noconfirm -Swu
fi

# Reinstall Official dependencies?
echo -n "Re-install Official dependencies? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read offdep

if [ $offdep = "y" ]; then
  sudo pacman -S --asdeps $(pacman -Qq | grep -vx "$(pacman -Qqe)" | grep -vx "$(pacman -Qqm)")
fi

# Re-install Official explictis?
echo -n "Re-install Official explicits? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read offexp

if [ $offexp = "y" ]; then
  sudo pacman -S $(pacman -Qqe | grep -vx "$(pacman -Qqm)")
fi

# Re-install Local depedencies
  echo -n "Re-install Local dependencies? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read locdep

if [ $locdep = "y" ]; then
  # Re-install package if cached, build others
  locdepls=$(pacman -Qqm | grep -vx "$(pacman -Qqme)")

  for pkg in $locdepls; do
    pkgver="$locpkgcache/$pkg-$(pacman -Qii $pkg | grep Version | awk '{ printf $3 }')-$(uname -m).pkg.tar.gz"
    if [ -f $pkgver ]; then
      sudo pacman -U --asdeps --noconfirm $pkgver
    else
      yaourt -S --asdeps --noconfirm $pkg
    fi
  done
fi

# Re-install Local explicits
  echo -n "Re-install Local explicits? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read locexp

if [ $locexp = "y" ]; then
  # Re-install package if cached, build others
  locexpls=$(pacman -Qqme)

  for pkg in $locexpls; do
    pkgver="$locpkgcache/$pkg-$(pacman -Qii $pkg | grep Version | awk '{ printf $3 }')-$(uname -m).pkg.tar.gz"
    if [ -f $pkgver ]; then
      sudo pacman -U --asexplicit --noconfirm $pkgver
    else
      yaourt -S --noconfirm $pkg
    fi
  done
fi

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

Offline

#880 2010-03-06 04:35:45

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 876
Website

Re: Post your handy self made command line utilities

recheck - regular expression validator, also supports groups like so:

» perl recheck.pl
S: foo bar baz zing
P: (\S+)\s(\S+)\s(.)(.)(.)\s(.+)
> foo bar baz zing <
[foo] [bar] [b] [a] [z] [zing]

#!/usr/bin/perl 
#recheck

use strict;
use warnings;

#die "$0 STRING PATTERN" if !@ARGV;
#my $string = shift;
#my $pattern = shift;

while(1) {
  print "S: "; my $string  = <STDIN>; exit 0 if $string =~ /:q/;
  print "P: "; my $pattern = <STDIN>; exit 0 if $string =~ /:q/;

  chomp($string, $pattern);
  eval{qr/$pattern/}; die if $@;

  my $c  = "\033[31;1m"; 
  my $c0 = "\033[0m";

  print ">$c $& $c0<\n" if $string =~ /$pattern/;
  foreach my $i(1..$#-) {
    print ' [', $c, substr($string, $-[$i], $+[$i] - $-[$i]), $c0, ']';
  }
  print "\n";
}

Offline

#881 2010-03-06 09:30:11

eco
Member
From: netherlands
Registered: 2009-07-02
Posts: 13

Re: Post your handy self made command line utilities

hello
I was looking for something like this for a long time but couldn`t find it. So after a while i thought, why not write it myself.
It is my first attempt at writing a script so improvements are welcome.
I use this script with awesomewm so that i get nice "nauthty" pupups. I haven`t tested it with other wm/de.
Also i would really like to add "clickable" notifications that show the email`s content when i click them. Then I don`t have to open mutt everytime i get an email. It would be great if someone could give me a hint in the right direction.
thanks

#!/usr/bin/perl -w

# MAILDIRCHECK, SCRIPT FOR CHECKING MAILDIRS ;)
#  - scans folders for new messages
#  - outputs a popup notification via "notify-send"
#  - great for use witch console mail apps like "mutt"

# put in crontab for automated checking every 5 minutes                               
#  - run: crontab -e                                                                
#  - add entry: */5 * * * * /path/to/mailcheck.pl >/dev/null 2>&1                   
#    or if you use "offlineimap":
#    */10 * * * * /usr/bin/offlineimap -u Noninteractive.Quiet >/dev/null 2>&1 &&  /path/to/mailcheck.pl >/dev/null 2>&1
#  - restart crond daemon                                                           

# TODO:
#  - make notifications clickable, expand notification to show email
#  - get rid of "cannot access" output

# by: eco                                                                     
# for questions and/or improvements please mail me at "flevosap at gmail dot com"     

#### edit here ####
$maildir="";                                        # set location of maildir. eg. "/home/<user>/mail"
                                                                     # set wich maildirs to check. eg. "gmail/inbox gmail/arch_forum" 
                                                                     # etc. (do not use quotes or comma`s)
@checkdirs=qw();
$time=0;                                                             # time in ms for notifications to stay on the screen, 0 = forever
$urgency="normal";                                                   # urgency level of popup (low,normal,critical)
$datafile_new="/home/nn/.maildircheck.new";
$datafile_old="/home/nn/.maildircheck.old";
$datafile_comm="/home/nn/.maildircheck_commfile";
#### stop editing here ####

if (-e $datafile_new) {
open (DEL, "rm $datafile_new |");                                    # remove $datafile_new if it exists
close DEL;
}

if (-e $datafile_comm) {
open (DEL, "rm $datafile_comm |");                                   # remove $datafile_comm if it exists
close DEL;
}

foreach $dir (@checkdirs) {                                          # cycle through dirs in @checkdirs
   $dir_open=$maildir."/".$dir."/new/*";                             # $dir = complete path to "new" dir
   open (WRITE_NEW, "ls -d $dir_open >>  $datafile_new  |") or die;  # for each dir: add "ls" output to $datafile_new
   close WRITE_NEW;
}

if (-e $datafile_old) {                                              # IF $datafile_old exists =>
   open (COMM, "comm -23 --nocheck-order $datafile_new $datafile_old >$datafile_comm |") or die; # compare two files and write to file
   close COMM;

   open (COMMFILE, "< $datafile_comm") or die;                       # open $atafile_com, put content in @newfiles
   @newfiles=<COMMFILE>;
   close COMMFILE;

   open (MOVE_NEW_OLD, "cp $datafile_new $datafile_old |") or die;   # move $datafile_new to $datafile_old
   close MOVE_NEW_OLD;
}

else {                                                               # IF $datafile_old doesn`t exist =>
   open (READ_NEW, "< $datafile_new") or die;                        # open $datafile_new, put content in @newfiles
   @newfiles=<READ_NEW>;
   close READ_NEW;

   open (MOVE_NEW_OLD, "cp $datafile_new $datafile_old |") or die;   # move $datafile_new to $datafile_old
   close MOVE_NEW_OLD;
}

foreach $file (@newfiles) {                                          # cycle through files in @newfiles
   chomp ($file);                                                    # get rid of \n at end of lines        

   open (DATA_FROM, "cat $file | grep 'From: ' |") or die "Couldn't execute program: $!";       # extract "From:" line from $file
   $from = <DATA_FROM>;
   close DATA_FROM;
                                                                         
   open (DATA_SUBJECT, "cat $file | grep 'Subject: ' |") or die "Couldn't execute program: $!"; # extract "Subject:" line from $file
   $subject = <DATA_SUBJECT>;                                                               
   close DATA_SUBJECT;                                                   

   chomp ($from);                                                    # get rid of \n at end of line
   chomp ($subject);
   $from =~ s/"//g;                                                  # get rid of " in variable
   $subject =~ s/"//g;
   $from =~ s/</(/g;                                                 # get rid of < in variable
   $subject =~ s/</(/g;
   $from =~ s/>/)/g;                                                 # get rid of > in variable
   $subject =~ s/>/)/g;

   foreach $dir (@checkdirs){                                        # cycle through dirs till $file contains one of the dirs in @checkdirs
      if ($file =~ $dir){                                            
         $newdir=$dir;
      }
   }
   # send out notification
   open (OUTPUT, "notify-send -u $urgency -t $time \"new message:\" \"in: $newdir\n$from\n$subject\" |")   or die "Couldn't execute program: $!"; 
   close OUTPUT;
}

Last edited by eco (2010-03-06 17:38:01)


"All programs can be optimized, and all programs have bugs; therefore all programs can be optimized to one line that doesn’t work."

Offline

#882 2010-03-06 09:36:15

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 876
Website

Re: Post your handy self made command line utilities

@eco use strict

Offline

#883 2010-03-06 19:45:55

Sirupsen
Member
From: Denmark
Registered: 2009-11-14
Posts: 26
Website

Re: Post your handy self made command line utilities

I recently made an extremely simple script, which basically uses Scrot to make you select a region, and take a screenshot. Hereafter, the screenshot is uploaded to my FTP server, and the URL is injected into my clipboard once the image was successfully uploaded - a message via libnotify is shown as well.

However, it's a very simple script, should anybody know of anything a bit better - while still maintaining the ease of use, and speed - please go ahead and link me! smile

Anyhow, I find it to a lot of use, hopefully you will too.

#!/bin/bash

FTPSERVER=
USERNAME=
PASSWORD=
dir=~/Photos/Screenshots

filename=shot$(date +%Y-%m-%d_%H%M%S)

url=http://example.com/screenshots

scrot -s -q 1  "$dir/$filename.png"

ncftpput -V -u $USERNAME -p $PASSWORD   $FTPSERVER /var/www/html/pic $dir/$filename.png

echo "$url$filename.png" | xclip -selection c
notify-send "Image uploaded to $url$filename.png"

exit

Relies on quite a few libraries, you can see these throughout the simple code.

Offline

#884 2010-03-06 19:55:10

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 876
Website

Re: Post your handy self made command line utilities

I'm doing the same thing like this:

scrot -e 'scp -P 19216 $f scp1@192.168.1.33:/srv/http/psy/scrots && rm $f && echo "http:/myhost/scrots/$f"|xclip'

Offline

#885 2010-03-06 20:01:49

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

Re: Post your handy self made command line utilities

Make sure to check that DISPLAY is set before running

Offline

#886 2010-03-06 21:51:28

Sirupsen
Member
From: Denmark
Registered: 2009-11-14
Posts: 26
Website

Re: Post your handy self made command line utilities

@dmz: Thanks for letting me have a look at your code; it's amazing what you can do in one line.

Offline

#887 2010-03-09 17:48:01

Moose9999
Member
Registered: 2010-03-09
Posts: 32

Re: Post your handy self made command line utilities

Here is my killwine script, I use it a lot when windows games freeze up in wine:

#/bin/bash 
#This script should kill any runaway wine programs
pid=$(ps -e | grep .e | cut -c 2-5) 
kill $pid

"The beautiful thing about learning is nobody can take it away from you."
B.B. King

Offline

#888 2010-03-09 17:57:05

simongmzlj
Member
From: Canada
Registered: 2008-11-06
Posts: 135

Re: Post your handy self made command line utilities

Moose9999 wrote:

Here is my killwine script, I use it a lot when windows games freeze up in wine:

#/bin/bash 
#This script should kill any runaway wine programs
pid=$(ps -e | grep .e | cut -c 2-5) 
kill $pid
wineserver -k

Offline

#889 2010-03-09 20:10:59

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

Re: Post your handy self made command line utilities

#!/bin/bash

export BOOKMARK_DB=${HOME}/.bm.db

bm(){
        arg=$1;
        if [[ "$arg" = "init" ]]; then
                rm "${BOOKMARK_DB}"
                echo "CREATE TABLE bookmarks(bookmark text primary key, path text);" |
                sqlite3 "${BOOKMARK_DB}"
        elif [[ "${arg:0:1}" = '+' ]]; then
                arg="${arg:1}"
                if [ -z "$2" ]; then
                        path="$(pwd)"
                else
                        path="$2"
                fi
                echo "INSERT INTO bookmarks VALUES('${arg}','${path}');" |
                        sqlite3 "${BOOKMARK_DB}"
        elif [[ "${arg:0:1}" = '-' ]]; then
                arg="${arg:1}"
                echo "DELETE FROM bookmarks WHERE bookmarks.bookmark='${arg}';" |
                        sqlite3 "${BOOKMARK_DB}"
        else
                path="$(
                        echo "SELECT path FROM bookmarks WHERE bookmarks.bookmark='${arg}';" |
                        sqlite3 "${BOOKMARK_DB}"
                )"
                if [ -z "$path" ]; then
                        echo "bookmark not recognised."
                elif ! cd "$path" >/dev/null; then
                        echo "Unable to CD to bookmark '$arg'"
                        echo "Loaded path $path"
                fi
        fi
}

A bash bookmark for quick hopping around. Source it or include it in your .bashrc file.
Usage($ indicates lines written, everything else is output):

$ bm init ## create database
$ bm +h ~ ## create one for home
$ bm +d ~/Desktop ## one for my Desktop
$ bm +m ~/music ## for my music
$ pwd
/home/scragar/Desktop/Sorted/iso
$ bm +iso ## for the current directory
$ bm h
$ pwd
/home/scragar
$ bm m
$ pwd
/home/scragar/music
$ bm iso
$ pwd
/home/scragar/Desktop/Sorted/iso
$ ## Now for the really fun stuff
$ bm +t ~/test
$ bm t
Unable to CD to bookmark 't'
Loaded path ~/test
$ bm -t
$ bm t
bookmark not recognised.

Still needs some work so you don't need to delete and recreate a bookmark to change it, but so far I like it tongue

Last edited by scragar (2010-03-09 21:52:56)

Offline

#890 2010-03-09 22:51:43

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Post your handy self made command line utilities

dmz wrote:

I'm doing the same thing like this:

scrot -e 'scp -P 19216 $f scp1@192.168.1.33:/srv/http/psy/scrots && rm $f && echo "http:/myhost/scrots/$f"|xclip'

Oh man that's great! I was looking for something like this the other day, thanks a lot. Added -s -q 1 as per Sirupsen's script to select region. Egg-sealant big_smile

Offline

#891 2010-03-10 00:49:11

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

Re: Post your handy self made command line utilities

That is good.  Sqlite, man that's hardcore.  Might just use that and save space in my bashrc.


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

Offline

#892 2010-03-12 06:23:35

Michael C.
Member
From: Vancouver, BC
Registered: 2009-12-16
Posts: 33

Re: Post your handy self made command line utilities

Very simple script to pick a WM when starting X:

#!/bin/bash

# Selects a window manager to use.

die()
{
    [ -n "$1" ] && echo "$1"
    exit 1
}

WM="$1" && shift
[ -z "$WM" ] && die "no window manager selected"

case "$WM" in
    openbox)
        WM_COMMAND="openbox-session"
        ;;

    awesome)
        WM_COMMAND="awesome"
        ;;

    *)
        die "invalid window manager"
        ;;
esac

export WM_COMMAND
startx "$@"
unset WM_COMMAND

Offline

#893 2010-03-12 07:10:14

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 876
Website

Re: Post your handy self made command line utilities

@ scragar: I really think you should work on that one, it has potential!

Offline

#894 2010-03-12 08:37:35

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 237
Website

Re: Post your handy self made command line utilities

@scragar: i suggest you take a look at cdargs. I tried it some months ago for a short time and  iirc it does something similar to your script.

Offline

#895 2010-03-12 11:28:54

gladstone
Member
Registered: 2009-01-03
Posts: 74

Re: Post your handy self made command line utilities

@scragar: sqlite? Seems a bit overkill to me. There's also: cdbm.

Offline

#896 2010-03-12 17:43:42

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

Re: Post your handy self made command line utilities

In response to the large number of comments I should explain that my goal was not to produce some awesome piece of software, but two fold, get a good understanding of sqlite from bash, and to avoid my current directory problems(Desktop/Sorted/iso/games/windows/RPG... Way too long).

If people do enjoy it and want me to continue it I will do so(probably best not to flood this thread though), but it really served it's purpose before I first posted it, I thought someone else might enjoy the code, draw inspiration from it, or whatever.

Offline

#897 2010-03-12 23:04:07

leadghost
Member
Registered: 2009-09-09
Posts: 29

Re: Post your handy self made command line utilities

I know this is silly (and probably wrong) but I find myself using it all the time now. It's amazing how often the results are either the arch wiki or the forums smile

#google lucky search
lucky() {
            local term="$*"
            [ -z "$term" ] && term="$(xclip -o)"
        local URL="http://www.google.com/search?btnI=I%27m+Feeling+Lucky&q=${term// /+}"
                 vimprobable "$URL" &>/dev/null &
         }


Hand over the spoon Milt...

Offline

#898 2010-03-14 06:47:29

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

Re: Post your handy self made command line utilities

I was playing around with redirection to /dev/pts and came up with this retarded, but entertaining script:

#!/bin/bash
[ ! "$1" ] && {
        echo "Usage: matrix <pts-number>"
        echo "Grabs control of a terminal and sends the Matrix message."
        echo
        echo "Choose a pts number:"
        echo -e "Number\tUser\tName"
        ps aux | awk '/pts\// && /bash/ {print $7":\t("$1")\t"$11}'
        exit
}

{
        tput civis
        echo -e "\r"
        clear

        echo "Wake up, ${USER^}..."
        sleep 4
        clear

        s="The Matrix has you..."
        for ((i=0;i<${#s};i++)); do
                echo -n "${s:$i:1}"
                case $i in
                        [0-2])          sleep 0.5;;
                        [3-6])          sleep 0.2;;
                        [7-8])          sleep 0.5;;
                        [9-11])         sleep 0.2;;
                        [12-13])        sleep 0.5;;
                        *)              sleep 0.2;;
                esac
        done
        sleep 3
        clear

        s="Follow the white rabbit."
        for ((i=0;i<${#s};i++)); do
                echo -n "${s:$i:1}"
                sleep 0.05
        done
        sleep 3.5 
        clear

        echo "Knock. Knock. ${USER^}."
        sleep 2.5 
        tput reset
        clear

} > /dev/pts/$1

Offline

#899 2010-03-14 08:54:43

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

Re: Post your handy self made command line utilities

^cool script. big_smile

Last edited by vik_k (2010-03-14 08:55:34)


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

Offline

#900 2010-03-14 09:49:48

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 679
Website

Re: Post your handy self made command line utilities

My spin on the screenshot script.  My script also creates a thumbnail for me and posts it to my server.  Also in my clipboard I have the exact piece of forum code needed to post my screenshot.

Thanks to Sirupsen and dmz with the initial script, this will save me so much time.

#!/bin/bash

SHOT="`date +%y%m`.png"
SHOTTHUMB="`date +%y%m`t.png"
SERVER=192.168.1.10
SERVERDIR="/srv/httpd/htdocs/linux/shots"
SERVERURL="http://www.foxjames.co.uk/linux/shots"
SHOTDIR="/tmp"


scrot $SHOTDIR/$SHOT
cp $SHOTDIR/$SHOT $SHOTDIR/$SHOTTHUMB
mogrify -resize 25% $SHOTDIR/$SHOTTHUMB

scp $SHOTDIR/$SHOT $USER@$SERVER:$SERVERDIR
scp $SHOTDIR/$SHOTTHUMB $USER@$SERVER:$SERVERDIR

echo "[url=$SERVERURL/$SHOT][img]$SERVERURL/$SHOTTHUMB[/img][/url]" | xclip

Last edited by gazj (2010-03-14 10:00:53)

Offline

Board footer

Powered by FluxBB