You are not logged in.

#176 2009-02-05 22:19:19

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

Re: Post your handy self made command line utilities

I'm not sure of the plumbing underneath, but a look at namcap might be worth your time, since it may already have a PKGBUILD class.

Offline

#177 2009-02-05 23:17:02

Sharn
Member
Registered: 2008-01-02
Posts: 6

Re: Post your handy self made command line utilities

pointone wrote:

Another AUR helper... in Python!

I build my packages in ~/aur by hand. I'm not a trusting person, so I like to look through every PKGBUILD before building. I don't know how you guys can use that yogurt thing.

yaourt gives you a very very clear "pkgbuilds can be dangerous - would you like to edits the PKGBUILD file? [Y/n]"

10x easier than doing it by hand. (Especially the automatic dependency checking)

Offline

#178 2009-02-06 01:48:27

munkyeetr
Member
From: Merritt, BC
Registered: 2008-08-07
Posts: 83

Re: Post your handy self made command line utilities

This is a random character generator I wrote a little over a year ago...I've gotten a few emails from people who came across it posted on another site and found it useful. Maybe someone here will also. I called it a "password generation program", but it's really just a character generator, not specific for passwords. tongue

munky

#!/usr/bin/perl

## ***************************************************************************
#
#  genpass v1.0 (06.2007) Password Generation Program
#  Copyright (C) 2007 Jon Brown
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  To read the full text go to http://www.gnu.org/licenses/gpl.txt
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
## ***************************************************************************

use strict;
use warnings;
use Getopt::Long;
Getopt::Long::Configure ("bundling");

## PARSE AND SET COMMAND-LINE OPTIONS
## -----------------------------------------------------
my %flags=('symbols', 0, 'numbers', 0, 'uppercase', 0, 'lowercase', 0, 'confusable', 0, 'help', 0, 'qty', 1, 'version', 0);

GetOptions( 's|S|symbols' => \$flags{symbols},
        'n|N|numbers' => \$flags{numbers},
        'u|U|uppercase' => \$flags{uppercase},
        'l|L|lowercase' => \$flags{lowercase},
        'c|C|confusable' => \$flags{confusable},
        'q|Q:i' => \$flags{qty},
        'help' => \$flags{help},
        'ver|version' => \$flags{version} );

# Set password characters, excluding those flagged on the command-line
my $pwdchars = join( '', map {chr} ( 0x21 .. 0x7e ));
    $pwdchars =~ s/\d+//    if ( $flags{numbers} );
    $pwdchars =~ s/[A-Z]+// if ( $flags{uppercase} );
    $pwdchars =~ s/[a-z]+// if ( $flags{lowercase} );
    $pwdchars =~ s/[_\W]+//g if ( $flags{symbols} );
    $pwdchars =~ tr/1Il0O//d  if ( $flags{confusable} );

# If user triggered the --help option flag, display and exit
if ($flags{help}) {           
    &DisplayUsage();   
    exit();
}
elsif ($flags{version}) {
    &DisplayVersion();
    exit();
}

## START VALIDATE INPUT
## -----------------------------------------------------
my $kill=0;        # flag to stop the script if input is invalid (or --help is used)
my @errmsg;        # error message descriptions

# If -q option was used to set a quantity of passwords, make sure it contains at
# least a value of 1 so that a password can be generated
if ($flags{qty} == 0 || $flags{qty} < 0) {
    $flags{qty}=1;
}

# Check that user hasn't excluded all character-types, warn user, kill script
if ( length($pwdchars) == 0) {
    push @errmsg, "** 0x1: At least 1 character-type must be included";   
    $kill=1;
}

# Check that user has passed only 1 argument (LENGTH) other than options flags, warn user, kill script
if ($#ARGV > 0 || $#ARGV < 0) {
    push @errmsg, "** 0x2: Incorrect number of arguments passed";
    $kill=1;
}

# Check for only numeric input in LENGTH argument, warn user, kill script
if ($ARGV[0] !~ /^[0-9]+$/) {
        push @errmsg, "** 0x3: Invalid input. LENGTH argument must be a numeric value";
        $kill=1;
}

# If any of the above validation tests triggered the $kill flag...
if ($kill == 1) {                    
    print "\n** GENPASS ERROR ---------------------------------------------------------";
    print "\n** ".@errmsg." Error(s) found";      # display number of errors   
    foreach my $err (@errmsg) {             # display error messages
        print "\n".$err;
    }
    print "\n**\n** Type genpass --help for command usage\n";
    print "** -----------------------------------------------------------------------\n\n";
    exit();                         # exit script
}
## END VALIDATE INPUT

## START MAIN SCRIPT
## -----------------------------------------------------
# From 1 to qty

for ( 1..$flags{qty} ) {
    print &GenPass( $ARGV[0] )."\n";
}
exit();

## END MAIN SCRIPT

## FUNCTION DEFINITIONS
## -----------------------------------------------------
sub GenPass() {
    my ($pwdlen) = @_;
    my $limit = length( $pwdchars );
    my $pwd = '';
   
    for ( 0..$pwdlen-1 ) {
            $pwd .= substr( $pwdchars, rand( $limit ), 1 );
    }

    return $pwd;
}

# use Here-Documents to display usage text
sub DisplayUsage {
    print <<"USAGE";

  Usage: genpass [-snulcqX] LENGTH
  Generate secure passwords LENGTH characters long.
   
    -s, --symbols\tExclude symbols.
    -n, --numbers\tExclude numbers.
    -u, --uppercase\tExclude uppercase letters.
    -l, --lowercase\tExclude lowercase letters.

    -c, --confusable\tExclude confusable characters like: l,I,1,0,O
       
    -qX\t\t\tCreate X number of passwords.
       
    --help\t\tDisplay Usage information.
    --ver, --version\tDisplay version and license information.
       
  Report bugs, comments, and questions to jbrown_home\@yahoo.ca
   
USAGE
}

# use Here-Documents to display version text
sub DisplayVersion {
print <<"VER";
  genpass v1.0 (06.2007) Copyright 2007 Jon Brown

  This is free software.  You may redistribute copies of it under the terms of
  the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
  There is NO WARRANTY, to the extent permitted by law.

  Written by Jon Scott Brown
VER
}
__END__

If the advice you're given in this forum solves your issue, please mark the post as [SOLVED] in consideration to others.

"More than any time in history mankind faces a crossroads. One path leads to despair and utter hopelessness, the other to total extinction.
Let us pray that we have the wisdom to choose correctly." -- Woody Allen

Offline

#179 2009-02-06 02:35:16

gregoryma
Member
From: Fredericton, Canada
Registered: 2008-12-15
Posts: 18

Re: Post your handy self made command line utilities

This is a little bash script I wrote to change between a dvorak and standard us keyboard layout.  I have a launcher on my Gnome panel run it.

Greg

#!/bin/bash

key_test=$(setxkbmap -print | grep xkb_symbols | sed 's|.*+\([^"]\+\).*|\1|')

if [ $key_test = "us(dvorak)" ]
then    
    setxkbmap us
elif [ $key_test = "us" ]
then
    setxkbmap dvorak
else
    setxkbmap dvorak
fi

Offline

#180 2009-02-06 07:40:54

bavardage
Member
Registered: 2008-02-17
Posts: 160

Re: Post your handy self made command line utilities

Doesn't gnome panel already have a keyboard switch widget?

It's a useful script for those not using gnome panel though big_smile

Offline

#181 2009-02-06 09:41:35

scj
Member
From: Sweden
Registered: 2007-09-23
Posts: 158

Re: Post your handy self made command line utilities

#!/bin/bash

# mmpc
# usage: mmpc (add|new) [term1] ... [termN]

cmd=$1
shift
terms=$(echo $* | sed -e 's#\(\w\+\)#| grep -i \1#g')
case "$cmd" in
    "new"    )
        mpc clear
        cmd="add"
        ;;
    esac
 
eval "mpc listall $terms | mpc $cmd -"
mpc play

Quick and dirty wrapper script for mpc. Will add all the files that contains all the terms you search for.

Offline

#182 2009-02-07 20:41:37

xstaticxgpx
Member
Registered: 2008-10-22
Posts: 48

Re: Post your handy self made command line utilities

wrote this script to simplify packing to multiple formats... currently supports .tar* (and abbreviations like .tb2 .tgz), .zip, .lzma, .bz2, .gz, and .7z - also plays well with globbing

#!/bin/bash
######################################################
#+ Simple archive script with multiple backends
#+ Rev. 3 - 2/07/09 - optimum.reflex@gmail.com
######################################################
hlp () { # Help function
    echo "usage: $0 [--help] [archive] [sources]"
    echo "[sources] is the files or folder you want added to the archive."
    echo
    echo "[archive] is the name of the archive generated, including extension."
    echo "Extensions are: .7z .zip .bz2 .gz .lzma .tar.*"
    exit 0
}

if [ $# -lt 2 ]; then # Need atleast an archive and one source
    hlp
fi

tarfunc () { # function that does the work
    MSG="packing [$SRCD] to [$DIR/$TAR]... "
    case "$TAR" in
        *.7z )
        echo -n $MSG
        /usr/bin/7z a -mx=9 $DIR/$TAR $SRC &>/dev/null
        ;;
        *.t* )
        echo -n $MSG
        /bin/tar -acZf $DIR/$TAR $SRC &>/dev/null
        ;;
        *.bz2 )
        echo -n $MSG
        /bin/bzip2 -cq9 $SRC > $DIR/$TAR
        ;;
        *.gz )
        echo -n $MSG
        /bin/gzip -cq9 $SRC > $DIR/$TAR
        ;;
        *.zip )
        echo -n $MSG
        /usr/bin/zip -qr9 $DIR/$TAR $SRC &>/dev/null
        ;;
        *.lzma )
        echo -n $MSG
        /usr/bin/lzma -cq9 $SRC > $DIR/$TAR
        ;;
        *)
        hlp;;
    esac
}

tdir () { # Determin target directory for archive
    if [ -d $1 ]; then
        if [ "$1" == "." ]; then
            DIR="$PWD"
        else
            DIR="$1"
        fi
    else
        DIR="$PWD"
    fi
}

case "$@" in
    *--help*) hlp;;
esac

TAR="`basename $1`"
tdir `dirname $1` && shift

if [ $# -gt 1 ]; then # If more than one source
    SRCD="$@" # all sources to $SRCD
    i=0 # counter
    while [ $1 ]; do
        if [ $i -eq 0 ]; then # only if the first source
            SRC="$1" && shift
            if [ ! -r "$SRC" ]; then
                echo "Location [$SRC] does not exist or is unreadable."
                exit 1
            fi
            ((i++)) # increment
        else # if sources after the first
            if [ ! -r "$1" ]; then
                echo "Location [$1] does not exist or is unreadable."
                exit 1
            fi
            SRC="$SRC $1" && shift # copy current $SRC and append next source
        fi
    done
    tarfunc # do the work
else # else if there is only one source
    SRC="$1"
        SRCD="$SRC" # copy $SRC
    if [ ! -r "$SRC" ]; then
        echo "Location [$SRC] does not exist or is unreadable."; exit 1
    elif [ -d "$SRC" ]; then # if source is a directory
        cd `dirname $SRC` # goto the directory one up from $SRC
        SRC="`basename $SRC`/" # change $SRC for correct directory packing structure
    fi
    tarfunc # do the work
fi

if [ $? -ne 0 ]; then # if last command failed
    cd $DIR
    rm -f $TAR && echo "failure detected, archive deleted."
    exit 1
else
    echo "success!"; exit 0
fi

Last edited by xstaticxgpx (2009-02-07 20:52:22)

Offline

#183 2009-02-08 11:00:07

bavardage
Member
Registered: 2008-02-17
Posts: 160

Re: Post your handy self made command line utilities

If irssi is not running, launch urxvt with a new screen session with irssi running inside it. If irssi is running (i.e. you closed the term window) it launches a urxvt and reconnects to the existing screen session. The term is named irc so it's easy to make wm rules for.

#!/bin/bash
if [ `screen -ls | grep irssi | wc -l` -ne 0 ]
then
    urxvt -name irc -title irc  -e sh -c "screen -dr `screen -ls | grep irssi | sed -e 's/(\(Attached\|Detached\))//'`"
else
    urxvt -name irc -title irc -e sh -c "screen -S irssi irssi"
fi

Offline

#184 2009-02-08 11:52:07

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

Re: Post your handy self made command line utilities

grep irssi | sed -e 's/(\(Attached\|Detached\))//'
sed -e '/irssi/s/(\(Attached\|Detached\))//'

Offline

#185 2009-02-09 10:54:24

aquila_deus
Member
From: Taipei
Registered: 2005-07-02
Posts: 348
Website

Re: Post your handy self made command line utilities

Remove unnecessary setuid attributes:

#!/bin/bash

find /bin /sbin /usr /opt /srv -perm -u=s -exec chmod u-s '{}' ';'
chmod u+s,o-rwx "/bin/su"
chmod u+s,o-rwx "/usr/local/lib/vmware/bin/vmware-vmx"
chmod u+s,o-rwx "/usr/local/sbin/vmware-authd"

find /bin /sbin /usr /opt /srv -perm -g=s -exec chmod g-s '{}' ';'

Start java with correct program name (set env JAVA_APPNAME in app launch scripts):

#! /bin/bash
if [ -z "${JAVA_APPNAME}" ]; then
  JAVA_APPNAME="java"
fi
JAVA_HOME=/opt/java
JAVA_TMPDIR=/tmp/java-tmpdir-${UID}
mkdir -p ${JAVA_TMPDIR}/bin
ln -sfT ${JAVA_HOME}/jre ${JAVA_TMPDIR}/jre
ln -fT ${JAVA_HOME}/jre/bin/java ${JAVA_TMPDIR}/bin/$JAVA_APPNAME
exec ${JAVA_TMPDIR}/bin/$JAVA_APPNAME $JAVA_OPTS "$@"

Offline

#186 2009-02-10 22:10:47

gnud
Member
Registered: 2005-11-27
Posts: 181

Re: Post your handy self made command line utilities

Ok, this one is probably one of the more obscure ones smile

I got some .eps files from a designer, that I couldn't open in any linux tool no matter what I did.

After some googling, i wrote this. Yes, it's hackish and silly (both the script and Adobe). But it works (again, both the script and Adobe).

#!/bin/sh
#

usage() {
    echo "psfix 0.1"
    echo "Usage: '$0 <file>'"
    echo
    echo "Strips Adobe Illustrator private data from (e)ps files."
    echo "Writes the fixed image to standard output."
    echo
    echo " (c) 2008 Sigmund Lahn"
}

process_file() {
    line=$(grep -n -a -F "%AI9_PrintingDataEnd" "${1}" | sed 's/\([0-9]*\).*/\1/')
    let ++line

    if [ $line -le 1 ]
    then
        #The file is not a strange adobe file, it's probably just 
        #a normal postscript file.
        #Output it unchanged, return success.
        #TODO: An argument flag that turns on some warning here
        #so that users know what is going on.
        cat "${1}"
        return 0
    else
        #The line number $line is the line after the data end,
        #including Illustrator comment.
        #
        head -n $line "${1}"
        return $?    
    fi
}

if [ $# -lt 1 ]
then
    usage 1>&2
    exit 1
fi

if [ -e $1 ]
then
    process_file $1
    exit $?
else
    echo "The file '$1' does not exist." 1>&2
    usage 1>&2
    exit 1
fi

Offline

#187 2009-02-10 22:41:25

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

Re: Post your handy self made command line utilities

basically yaourt-lite (i know there's a million of em, but this one's _mine_).

it'll google the aur, let you pick a package, download it, then optionally extract/build/install/remove the source (keep just the .pkg - or not) through y/n options.

i just realized i have no less than three bash scripts that interface directly with google... *cough*skynet*cough*

> cat Scripts/aurget
#!/bin/bash

# user defined DL directory
DIR=${HOME}/Packages/aur

# define some things for lynx based on your system
LNG=$(echo $LANG | cut -d '_' -f 1)
CHARSET=$(echo $LANG | cut -d '.' -f 2)

# error checking
if [ -z $1 ]; then
  echo "Please specify a search term. Ex. ./aurget cairo"
  exit 0
fi

# search google for AUR package
lynx -accept_all_cookies -dump -hiddenlinks=ignore -nonumbers -assume_charset="$CHARSET" -display_charset="$CHARSET" "http://www.google.com/search?hl=${LNG}&q=${1}+site%3Ahttp%3A%2F%2Faur.archlinux.org%2F&btnG=Search" | grep AUR\ \(en\) > /tmp/aur_results
if [ ! -s /tmp/aur_results ]; then
  echo "Sorry, no appropriate results."
  exit 0
fi

# display the results
echo "Results found:"
echo ""
#awk '{ print "  ", $_ }' /tmp/aur_results
cat -b /tmp/aur_results | awk '{ print "  ", $1, $3, $4, $5, $6 }'
echo ""
echo "Please enter the number to download: (or q to quit)"

# read which packages to DL
read NUM
if [ "$NUM" = "q" ]; then
  echo "Quitting..."
  exit 0
fi

PACK=$(cat -b /tmp/aur_results | grep -P "${NUM}\t" | awk '{ print $6 }')
rm /tmp/aur_results || exit 1

# do it!
clear
echo "Downloading ${PACK} to ${DIR}..."
wget -q -O ${DIR}/${PACK}.tar.gz http://aur.archlinux.org/packages/${PACK}/${PACK}.tar.gz

clear
echo "Package downloaded, the following are optional y/n options"
echo ""

# rest is optional depending on your level of douchey-ness
echo "Extract?"
read E
case $E in
  y)
  cd $DIR && tar xvzf ${PACK}.tar.gz || exit 1
  ;;
  n)
  echo "Quitting..."
  exit 0
  ;;
  *)
  echo "Invalid, quitting."
  exit 0
  ;;
esac

# use makepkg to build the package
clear
echo "Files extracted, the following are optional y/n options."
echo ""
echo "Build? Really?"
read B
case $B in
  y)
  cd ${DIR}/${PACK} && makepkg -s || exit 1
  ;;
  n)
  echo "Quitting..."
  exit 0
  ;;
  *)
  echo "Invalid, quitting."
  exit 0
  ;;
esac

# use pacman -U to install the package
clear
echo "Package built, the following are optional y/n options."
echo ""
echo "Install? Wow..."
read I
case $I in
  y)
  PACK=$(find $DIR -name '*pkg.tar.gz')
  sudo pacman -U ${PACK} || exit 1
  clear
  echo "Done."
  exit 0
  ;;
  n)
  echo "Quitting..."
  exit 0
  ;;
  *)
  echo "Invalid, quitting..."
  exit 0
  ;;
esac

# clean up the working directory, save the package if you want
clear
echo ""
echo "Package installed, remove source data (y/n)?"
read R
case $R in
  y)
  echo "Save the package itself?"
  read P
  if [ "$P" = "y" ]; then
    mv ${PACK} /home/patrick/Packages/
  fi
  rm -r ${DIR}/*
  exit 0
  ;;
  n)
  echo "source data left in ${DIR}, quitting..."
  exit 0
  ;;
  *)
  echo "Invalid, quitting..."
  exit 1
  ;;
esac

exit 0

edit: fixed grep (line ~17) to weed our more non-AUR results

Last edited by brisbin33 (2009-02-11 20:57:41)

Offline

#188 2009-02-12 22:04:41

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

Re: Post your handy self made command line utilities

I needed a kakasi wrapper, so I made one:
Needs kakasi from [community]

I put in an extra option to just convert kanji to hiragana, and to convert ascii to wide.

Usage:
dekanji kana 昔々 -> むかしむかし
dekanji 昔々 -> mukashimukashi
dekanji wide 'testing!@#$%' -> testing!@#$%

#! /bin/dash
if [ "$1" = "kana" ]; then
shift
echo $* | iconv -f utf-8 -t euc-jp | kakasi -o euc -JH | iconv -f euc-jp -t utf-8
elif [ "$1" = "wide" ]; then
shift
echo $* | iconv -f utf-8 -t euc-jp | kakasi -o euc -aE | iconv -f euc-jp -t utf-8
else
echo $* | iconv -f utf-8 -t euc-jp | kakasi -s -o euc -Ha -Ka -Ja -Ea -ka | iconv -f euc-jp -t utf-8
fi

Offline

#189 2009-02-13 15:27:56

wooptoo
Member
From: London
Registered: 2007-04-23
Posts: 71
Website

Re: Post your handy self made command line utilities

I'll post my scripts too. They are all in bash:

blame (usage: blame <path>)

#!/bin/sh
# batch lame encoder

find "$1" -name '*.wav' -type f -exec lame --replaygain-accurate -q2 -V0 --vbr-new {} \; -exec rm {} \;

cput (usage: cput <delay in seconds>)

#!/bin/sh
# display cpu fan & temp every given seconds

while (true) do
echo ""
sensors|grep CPU|cut -f 1 -d "("
sleep $1
done

The following script greatly simplifies bluetooth file transfers from my phone to my computer.
It scans for bluetooth devices using hcitool, and it mounts the first one found using obexfs. The device is mounted in /media/phone and can be accessed using any file manager.
The accompanying defuse script unmounts /media/phone.

fuse (usage: fuse phone)

#!/bin/sh

case "$1" in
    "phone")
        obexfs -b `hcitool scan|awk '{if (NR==2) print $1}'` -B 10 /media/"$1";;
esac

defuse (usage: defuse phone)

#!/bin/sh

fusermount -u /media/"$1"

smile

Offline

#190 2009-02-17 15:39:48

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

Re: Post your handy self made command line utilities

I wrote a small script to make urls tiny quickly. dependencies are curl and xclip (for convenience)
there are two possible ways to use this:
1. copy an url to the X clipboard, run the script (e.g. through a hotkey) and immediately paste the tinyurl again. smile
2. pass an URL as the first and only argument and tadaa, there is the tinified url on STDOUT (and also in the clipboard)

#!/bin/sh
#
# title: tinify
# author: Philip Stark
# desc:  pass an url as the first and only argument to make it tiny or 
#        leave it away and it takes the content of the clipboard by
#        calling xclip. 
# licenced under the WTFPL (http://sam.zoy.org/wtfpl/)
 
if [ "$1" = "" ]; then
  tinyurl=$(curl http://tinyurl.com/api-create.php?url=$(xclip -selection clipboard -o) 2> /dev/null)
  echo $tinyurl;
  echo $tinyurl | xclip -selection clipboard -i;
else
  url=$1;
  tinyurl=$(curl http://tinyurl.com/api-create.php?url=${url} 2> /dev/null)
  echo $tinyurl;
  echo $tinyurl | xclip -selection clipboard -i;
fi

version without xclip dependency (to keep it simple wink ):

#!/bin/sh
# title: tinify
# author: Philip Stark
# desc:  pass an url as the first and only argument to make it tiny or 
#        leave it away and it takes the content of the clipboard by
#        calling xclip. 
# licenced under the WTFPL (http://sam.zoy.org/wtfpl/)
[ "$1" == "" ] && echo "Usage: tinify url" && exit
url=$1;
tinyurl=$(curl http://tinyurl.com/api-create.php?url=${url} 2> /dev/null)
echo $tinyurl;

have fun
cheers Barde

Last edited by Heller_Barde (2009-02-17 18:51:03)

Offline

#191 2009-02-17 16:05:28

scj
Member
From: Sweden
Registered: 2007-09-23
Posts: 158

Re: Post your handy self made command line utilities

edit: nevermind, didn't see the thread.

edit 2: to contribute

#!/bin/bash

#rarplayer: simple script to pipe the contents of a rar file straight
#           to mplayer.

#extract any switches to pass them on to mplayer
cmd=""
for arg in $*; do
if [[ `expr index $arg "-"` -eq "1" ]]; then
    cmd="$cmd $arg"
    shift
fi
done

#to preserve whitespaces in filenames
files=("$@")
for file in "${files[@]}"; do
    unrar p -inul "$file" | mplayer $cmd -
done

Last edited by scj (2009-02-20 17:46:32)

Offline

#192 2009-02-23 18:47:54

lswest
Member
From: Munich, Germany
Registered: 2008-06-14
Posts: 454
Website

Re: Post your handy self made command line utilities

I wrote a python script just a few minutes ago to take all the .java files in a project folder of NetBeans and condense it into one text file for easier printing/copying, since my school requires a hard copy of my code (IB course) to send it to the examiners.  Thought it'd save me doing it per file (15 of them or so).

Here it is (has other uses as well):

#!/usr/bin/env python
#Script to condense the multiple files of a project into one for easy printing/copying
#Author: lswest
import os

home=os.path.expanduser("~")
ff=open(os.path.join(home,"condensedCode.txt"), "wt")
endPath=raw_input("Path relative to your home directory to the project folder: ")

for root, dirs, files in os.walk(os.path.join(home,endPath), "true", "none", "true"):
    for infile in [f for f in files if f.endswith(".java")]:
        fh=open(os.path.abspath(os.path.join(root,infile)))
        for line in fh:
            ff.write(line,)
        fh.close()
ff.close()

I'm still learning python so it's probably not as efficient as possible, and I know I could have allowed for user input for the output file, but I actually only added in the prompt for the first one since a friend of mine might also use the script to condense his code, and I wanted to make it easy enough for him to use without much trouble (since I emailed it to him).

Any constructive feedback is appreciated,
Lswest

*Edit* I had some extra time so I re-wrote it to allow specification of extension, input path, output path, output file name, etc.

#!/usr/bin/env python
#Script to condense the multiple files of a project into one for easy printing/copying
#Author: lswest
import os

home=os.path.expanduser("~")
endPath=raw_input("Path relative to your home directory to the project folder: ")
extension=raw_input("Extension of files you want to condense: ")
outPath=raw_input("Path to output file relative to home directory: ")
outFile=raw_input("Output file name (including extension): ")
ff=open(os.path.join(home+outPath,outFile), "wt")

for root, dirs, files in os.walk(os.path.join(home,endPath), "true", "none", "true"):
    for infile in [f for f in files if f.endswith(extension)]:
        fh=open(os.path.abspath(os.path.join(root,infile)))
        for line in fh:
            ff.write(line,)
        fh.close()

ff.close()

Last edited by lswest (2009-02-23 19:34:45)


Lswest <- the first letter of my username is a lowercase "L".
"...the Linux philosophy is "laugh in the face of danger". Oops. Wrong one. "Do it yourself". That's it." - Linus Torvalds

Offline

#193 2009-02-24 16:06:05

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Post your handy self made command line utilities

I recently just came up with this script to make it quicker to perform common package management tasks. I had previously used aliases in .bashrc, but I decided this was better. It would be fairly easy to adapt it for other package managers, and in fact, the syntax was supposed to be somewhat neutral in that sense. I currently use it with yaourt and powerpill.

#!/bin/sh
# 
# ~/bin/pm - shorthand frontend to package management tasks
# 

case $1 in
    c | clean )         sudo pacman -Sc --noconfirm
                        ;;
    i | ins | install ) shift
                        yaourt -S "$@"
                        ;;
    n | info )          shift
                        for arg in "$@"; do
                            pacman -Qi $arg 2> /dev/null || pacman -Si $arg
                        done
                        ;;
    l | ls | list )     shift
                        pacman -Ql "$@"
                        ;;
    o | own )           shift
                        for arg in "$@"; do
                            pacman -Qo `which $arg 2> /dev/null || echo $arg`
                        done
                        ;;
    q | query )         shift
                        yaourt -Qs "$@"
                        ;;
    r | rm | remove )   shift
                        sudo pacman -Rcs "$@"
                        ;;
    s | search )        shift
                        yaourt -Ss "$@"
                        ;;
    u | upg | upgrade ) yaourt -Syu --aur
                        ;;
    * )                 yaourt "$@"
esac
Examples:

Install a package from the repos:
pm i package
pm ins package
pm install package

Check which package owns a file:
pm o firefox (this will find firefox in the $PATH - no need for the full filename)
pm own /etc/rc.sysinit

Look for info on a package which is currently installed:
pm n package
pm info package

Look for info on a package which is not currently installed
    (note, this is the same as above! no more distinction between -Qi and -Si):
pm n package
pm info package

Do some other package management command with normal command line arguments:
pm -U --asdeps ./*.pkg.tar.gz

Last edited by fflarex (2009-02-24 16:10:19)

Offline

#194 2009-02-24 16:19:46

toxygen
Member
Registered: 2008-08-22
Posts: 705

Re: Post your handy self made command line utilities

fflarex wrote:

I recently just came up with this script to make it quicker to perform common package management tasks. I had previously used aliases in .bashrc, but I decided this was better. It would be fairly easy to adapt it for other package managers, and in fact, the syntax was supposed to be somewhat neutral in that sense. I currently use it with yaourt and powerpill.

that's a real nice and simple script.  thanks for sharing!


"I know what you're thinking, 'cause right now I'm thinking the same thing. Actually, I've been thinking it ever since I got here:
Why oh why didn't I take the BLUE pill?"

Offline

#195 2009-02-24 16:36:31

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

Re: Post your handy self made command line utilities

Nice work fflarex

Offline

#196 2009-02-25 18:08:12

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 847

Re: Post your handy self made command line utilities

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


pie!

Offline

#197 2009-02-25 20:23:29

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Post your handy self made command line utilities


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#198 2009-02-25 23:06:22

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

Re: Post your handy self made command line utilities

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?

Offline

#199 2009-02-26 00:09:39

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 847

Re: Post your handy self made command line utilities

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 ^^

---

Last edited by karabaja4 (2009-02-26 01:22:50)


pie!

Offline

#200 2009-02-26 01:59:39

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

Re: Post your handy self made command line utilities

The benefit to this of course, is that pacman manages everything for you, preventing innumerable issues

Offline

Board footer

Powered by FluxBB