You are not logged in.

#2226 2013-10-11 08:31:02

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Post your handy self made command line utilities

cfr wrote:

This thread makes me realise just how specific most of my scripts are. I just don't think anybody else would be at all interested.

Don't know if anybody would find this useful:

$ cat bin/antiwordx 
#!/bin/bash -

PATH=/usr/local/bin:/bin:/usr/bin; export PATH
allan=0

for i
do
        j="${i/\.docx/.zip}"
        d="${i/\.docx/}"
        cp -p "$i" "$j"
        if [ $? != 0 ]
        then
                ((allan++))
                continue
        else
                mkdir "$d"
                if [ $? != 0 ]
                then
                        ((allan++))
                        continue
                else
                        unzip -d "$d" "$j" > /dev/null
                        if [ $? != 0 ]
                        then
                                ((allan++))
                                continue
                        else
                                sed 's/<w:p[^>]*>/\n/g' "$d/word/document.xml" | sed -e 's/<[^>]*>//g'  -e '/^$/d' -e 's/$/\n/'
                                if [ $? != 0 ]
                                then
                                        ((allan++))
                                        continue
                                else
                                        rm -r "$d" "$j"
                                        if [ $? != 0 ]
                                        then
                                                ((allan++))
                                                continue
                                        fi
                                fi
                        fi
                fi
        fi
done

exit $allan
# vim: set nospell: 

This was written before OpenOffice could read .docx files and I just desperately needed to be able to read the damn things somehow. It is no prettier than the output of antiword but it is useful for extracting information quickly when that's all that's required.

Don't have any docx locally at the moment to try it, but that should be really useful for quickly reading docx mail attachments, inline. Many thanks.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#2227 2013-10-12 12:10:47

sekret
Member
Registered: 2013-07-22
Posts: 283

Re: Post your handy self made command line utilities

There's also docx2txt, which does a bit nicer formatting.

Offline

#2228 2013-10-12 20:07:30

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Post your handy self made command line utilities

sekret wrote:

There's also docx2txt, which does a bit nicer formatting.

Thanks for that - I'll give it a try.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#2229 2013-10-15 13:48:30

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,389

Re: Post your handy self made command line utilities

Some background first:
I've a pair of high end headphones and a pair of mid/high end loudspeakers that sounds very different due to wall reflections.
I like to play with audio tools and make music sometimes and i've found a filter chain (calf plugins) that makes my loudspeakers to sound more or less like my headphones; so i was in the need of inserting the calf plugins at the end of the jack connections, just before the real output.

What follows is a script that does that; it disconnect any jack client which is connected to the given output port, and connect it to another client/port of your choice; next it will connect the latter to the real output port:
It is much more easier than messing up with qjackctl patchbay definitions.

Works for stereo signlas only:

#!/bin/bash

#Configurable variables:

  # Manage clients connected to those ports:
    ROP1="system:playback_1"
    ROP2="system:playback_2"

  # Explicitely DO NOT manage clients matching:
    EXC="calf:stereo_out_"

  # reconnect managed clients to those ports instead:
    O1="calf:stereo_in_l"
    O2="calf:stereo_in_r"

#End of configurable variables


JACKOUT="^$ROP1\|^$ROP2"

D1=";"


#Clients connected to $JACKOUT:
PCLIENTS=$(jack_lsp -c|grep -vi $EXC|sed ':a;N;$!ba;s/\n /'"$D1"'/g;s/  //g'|grep $D1|grep $JACKOUT|cut -d $D1 -f 2-)

LCLIENTS=$(echo "$PCLIENTS"|head -n 1) #Left channel clients
RCLIENTS=$(echo "$PCLIENTS"|tail -n 1) #Right channel clients

OIFS=$IFS
IFS=$D1

for LCLIENT in $LCLIENTS; do
  echo $LCLIENT:
  echo "   Connecting to:     " $O1
  echo "   Disconnecting from:" $ROP1
  jack_connect    "$LCLIENT" "$O1" 	#connect the client to the new port
  jack_disconnect "$LCLIENT" "$ROP1"	#disconnect the client from the old port
done

for RCLIENT in $RCLIENTS; do
  echo $RCLIENT:
  echo "   Connecting to:     " $O2
  echo "   Disconnecting from:" $ROP2
  jack_connect    "$RCLIENT" "$O2" 	#connect the client to the new port
  jack_disconnect "$RCLIENT" "$ROP2"	#disconnect the client from the old port
done

IFS=$OIFS

#Make the final connections to hear something

jack_connect calf:stereo_out_l system:playback_1
jack_connect calf:stereo_out_r system:playback_2

Hint: Use jack_lsp -c to get client:port names.

Last edited by kokoko3k (2013-10-15 14:05:50)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#2230 2013-10-16 02:38:19

dz
Member
Registered: 2013-08-21
Posts: 16

Re: Post your handy self made command line utilities

I wrote a daemon for isync that monitors an IMAP server with IDLE and runs mbsync when a new email arrives.  Basically, push email for isync.  It's able to parse mbsyncrc (including the new PassCmd directive) but doesn't support multiple accounts.  Looking for ways to improve it.

https://github.com/devlinzed/dotfiles/b … in/mbsyncd

Offline

#2231 2013-10-20 20:54:32

bnb2235
Member
Registered: 2011-02-13
Posts: 119

Re: Post your handy self made command line utilities

Hello everyone,
I just thought I would post a script here which I made to resize images in Thunar. Until yesterday, I used Nautilus (on Gnome desktop) and the script found here. I merged that script, along with a script from here and here. The last script has a progress bar, but for me it did not work when more than 100 images were selected. So anyway, I post my script here on the bbs. It would be great if someone with more skill than me could tidy it up and make it a bit more professional. BTW, why can't I get the listbox to show all three of my selections at once without scrolling thru them? Setting the height of the listbox only resizes the entire form, but the listbox region remains one line... For reference, I copied the script to /usr/local/bin with the name resize (set it executable). Then add the custom action "Resize image(s)..." with command "resize %N" Under "Appearance Conditions", "image files" is checked.

#!/bin/sh                                                                                                                     

TOTALPICS="$(($#))"
STEP=$(echo 100 / $TOTALPICS | bc -l)
PROGR=0

title="Choose Maximum Dimension"
imgsize=`zenity --title "$title"  --list  --height=210 --column="Maximum Dimension" "640" "800" "1024"`
 

#if $? != 0, user click on cancel button, so exit
if [ "$?" != 0 ] ; then
	exit
fi

#user must select a target size

if [ ! "$imgsize" ]; then
	zenity --error --title="Error" --text="Select a target size!"
	exit
fi

mkdir -p ./Resized/$imgsize

for file
    do
    if [ ! -e $file ]
        then
        continue
    fi
    toname="./Resized/"$imgsize"/"$( echo $file | cut -f1 -d.)".jpg"
    convert -geometry "${imgsize}x${imgsize}" -quality 80 "${file}" "${toname}"
     PROGR=$(echo $PROGR + $STEP | bc)
     echo $PROGR
     shift
done | zenity --progress --title="Picture Resize" --text="working..." --percentage=0 --auto-close

# check return value and print message depending on it
 [[ $? == 0 ]] && zenity --info --title="Picture Resize" --text="All done!" || zenity --warning --text="Canceled before completed!" 

Edit 10/27/2013:
Sometime between when I originally posted this and now, my listbox height problem has gone away. Therefore, I added "--height=210" to the script.

Last edited by bnb2235 (2013-10-28 00:49:36)

Offline

#2232 2013-10-20 21:15:37

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,728

Re: Post your handy self made command line utilities

Merging " Thunar Custom action to resize images" with main "Handy Command Line Utilities" thread


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#2233 2013-11-01 13:49:00

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,389

Re: Post your handy self made command line utilities

My "smartstart.sh"

#!/bin/bash
nice -n -10 "$@" &
LASTPID=$!
sleep 30
renice -n 0 -p $LASTPID
wait $LASTPID

The idea is to start a process with a higher priority and to set it back to 0 after a while to hopefully make it start faster; works good with firefox when i resume from hibernation and other automated actions are taking place...

Note that the user has to gain rights to use lower nice levels by editing /etc/security/limits.conf, but the default for audio users is already set to -10

Last edited by kokoko3k (2013-11-01 13:50:16)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#2234 2013-11-04 13:36:02

aaditya
Member
Registered: 2013-09-01
Posts: 174

Re: Post your handy self made command line utilities

Bash command/alias for displaying the last upgrade time


A command to display the last upgrade time-

echo -e "\e[1;31mLast Upgraded:\e[0m " ; tac /var/log/pacman.log | grep upgraded | head -n 1 | cut -c 2-17

Bash alias-

alias lastup='echo -e "\e[1;31mLast Upgraded:\e[0m " ; tac /var/log/pacman.log | grep upgraded | head -n 1 | cut -c 2-17'

With a little more details-

cat /var/log/pacman.log | grep upgraded | tail -n 10

Bash alias-

alias lastupd='cat /var/log/pacman.log | grep upgraded | tail -n 10'

Edit-
Sorry If I have posted it in the wrong sub forum. Does it need to be in the programming sub-section?

Last edited by aaditya (2013-11-04 14:00:27)

Offline

#2235 2013-11-04 13:47:45

Awebb
Member
Registered: 2010-05-06
Posts: 6,268

Re: Post your handy self made command line utilities

https://bbs.archlinux.org/viewtopic.php?id=56646

Edit: Edit your title into the post, this way it can be found even after it has been merged with the other thread (I assume it will).

Last edited by Awebb (2013-11-04 13:48:28)

Offline

#2236 2013-11-04 13:59:34

aaditya
Member
Registered: 2013-09-01
Posts: 174

Re: Post your handy self made command line utilities

Awebb wrote:

https://bbs.archlinux.org/viewtopic.php?id=56646

Edit: Edit your title into the post, this way it can be found even after it has been merged with the other thread (I assume it will).

Thx Awebb smile

Last edited by aaditya (2013-11-04 14:19:35)

Offline

#2237 2013-11-04 14:03:21

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

'grep upgraded /var/log/pacman.log | tail -n10' is enough. No need for the 'cat'.
See also https://bbs.archlinux.org/viewtopic.php … 87#p626487

Offline

#2238 2013-11-04 14:06:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,422
Website

Re: Post your handy self made command line utilities

tac + grep + head + cut = awk.

awk '/upgraded/ {line=$0;} END { $0=line; gsub(/[\[\]]/,"",$0); printf "\033[1;31mLast Upgraded:\033[0m %s %s\n",$1,$2;}' /var/log/pacman.log 

Thanks Karol (below).  My prompt ensures there's a newline before printing so I didn't catch that.  But something did look a bit off.

Last edited by Trilby (2013-11-04 14:10:13)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#2239 2013-11-04 14:08:30

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

Trilby wrote:

tac + grep + head + cut = awk.

awk '/upgraded/ {line=$0;} END { $0=line; gsub(/[\[\]]/,"",$0); printf "\033[1;31mLast Upgraded:\033[0m %s %s",$1,$2; exit;}' /var/log/pacman.log 

Can I has a newline?

awk '/upgraded/ {line=$0;} END { $0=line; gsub(/[\[\]]/,"",$0); printf "\033[1;31mLast Upgraded:\033[0m %s %s\n",$1,$2; exit;}' /var/log/pacman.log

Offline

#2240 2013-11-04 14:19:20

aaditya
Member
Registered: 2013-09-01
Posts: 174

Re: Post your handy self made command line utilities

Thx Karol and Trilby smile

Offline

#2241 2013-11-04 16:25:11

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Post your handy self made command line utilities

Merging...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#2242 2013-11-05 18:11:02

frojnd
Member
Registered: 2008-09-20
Posts: 125

Re: Post your handy self made command line utilities

I thouth I'd solve annoying blank screen after 10 minutes when watching flash in full screen for xmonad.

So I was searching and I found this program written in c. Unfortunatelly it didn't work for me.

So here is my script that works in xmonad. checkflash.hs on github. There are flaws like if video is is paused and in full screen, screen saver will still be disaabled. Something I might fix in the future if I'll ever need it.

Last edited by frojnd (2013-11-05 18:12:28)

Offline

#2243 2013-11-06 05:22:03

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: Post your handy self made command line utilities

@ frojnd, you can also use a script to generate false mouse movement or clicks at a set interval using something like xdotool. In theory, it should work.

Offline

#2244 2013-11-06 08:06:58

kaszak696
Member
Registered: 2009-05-26
Posts: 543

Re: Post your handy self made command line utilities

Personally, i prefer the manual approach for this, and made a keybind that turns DPMS on/off on press.


'What can be asserted without evidence can also be dismissed without evidence.' - Christopher Hitchens
'There's no such thing as addiction, there's only things that you enjoy doing more than life.' - Doug Stanhope
GitHub Junkyard

Offline

#2245 2013-11-07 15:35:00

SolarBoyMatt
Member
Registered: 2012-01-07
Posts: 263

Re: Post your handy self made command line utilities

I'm sure this has been done to death, but I wrote a short script to check for new mail and send a notification with libnotify if there are new ones.

#!/usr/bin/bash

offlineimap -o -q -u quiet

new=$(ls ~/Mail/matthome/INBOX/new | wc -l)
old=$(ls ~/Mail/matthome/INBOX/cur | wc -l)

if [ $new -gt 0 ] 
then
    export DISPLAY=:0; export XAUTHORITY=~/.Xauthority; notify-send -a "OfflineIMAP" "New mail!\nNew: $new Old: $old"
fi

Works just fine in a crontab, but I haven't been able to get it to work with a systemd timer yet.

Last edited by SolarBoyMatt (2013-11-07 15:42:51)

Offline

#2246 2013-11-07 16:23:39

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Post your handy self made command line utilities

Why you shouldn't parse the output of `ls`.

maildirs="$HOME/Mail/*/INBOX/new/"
ml="$(find $maildirs -type f | wc -l)"

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#2247 2013-11-07 16:30:02

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Post your handy self made command line utilities

If in bash:

shopt -s nullglob
files=( "$maildir"/* )
echo ${#files[@]}
shopt -u nullglob

Offline

#2248 2013-11-07 19:40:00

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,389

Re: Post your handy self made command line utilities

jasonwryan wrote:

Why you shouldn't parse the output of `ls`.

maildirs="$HOME/Mail/*/INBOX/new/"
ml="$(find $maildirs -type f | wc -l)"

Unfortunately find used that way (as stated on that site) doesn't seem to be better:

kokonicki@netbook /tmp/prova $ touch 'a space' $'a\nnewline'
kokonicki@netbook /tmp/prova $ echo "don't taze me, bro" > a
kokonicki@netbook /tmp/prova $ ls -1
a
a?newline
a space
kokonicki@netbook /tmp/prova $ ls |cat
a
a
newline
a space
kokonicki@netbook /tmp/prova $ find . -type f
./a
./a space
./a?newline
kokonicki@netbook /tmp/prova $ find . -type f|wc -l
4

Seems the only way to avoid a for loop with a counter is to use find to terminate the filenames with NUL instead of \n, but i'm unable to do it:

kokonicki@netbook /tmp/prova $ find -type f -print0
./a./a space./a
newlinekokonicki@netbook /tmp/prova $ find -type f -print0|wc -l
1

So, what to do?


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#2249 2013-11-07 21:32:31

Earnestly
Member
Registered: 2011-08-18
Posts: 805

Re: Post your handy self made command line utilities

http://mywiki.wooledge.org/UsingFind
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/BashPitfalls

Using find like that is also wrong.
What steve above did was more correct but you should really use printf in scripts.

Last edited by Earnestly (2013-11-07 21:33:28)

Offline

#2250 2013-11-07 23:22:17

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: Post your handy self made command line utilities

Hello!

Top 20 largest subdirs in current directory:

/usr/bin/du -xh ./ | sort -h -r | head -n 20

Simple MIME editor written in fish. Very handy when xdg-open opens files with wrong desktop file (ls /usr/share/applications/*.desktop).

$ cat ~/.config/fish/functions/mime.fish 
function mime
        set c (count $argv)
        if test $c -eq 0
                echo Usage:
                echo mime FILE \# gets mime desktop
                echo mime FILE file.desktop \# sets mime desktop
                return
        end

        set mimetype (/usr/bin/xdg-mime query filetype $argv[1])
        set mimedefault (/usr/bin/xdg-mime query default $mimetype)

        if test $c -eq 2
                set mimedefault $argv[2]
                /usr/bin/xdg-mime default $mimedefault $mimetype
        end

        echo $mimetype\n$mimedefault
end


Example:
#gets MIME type and associated default application
> mime /usr/share/doc/fish/index.html
text/html
opera-browser.desktop

#sets default application 
> mime /usr/share/doc/fish/index.html firefox.desktop
text/html
firefox.desktop

Offline

Board footer

Powered by FluxBB