You are not logged in.

#1951 2012-09-25 19:31:20

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

Re: Post your handy self made command line utilities

Trilby wrote:

Sweet ... I wasn't familiar with xinput.  But FYI, "Mouse" would need to be adjusted for laptops with touch/trackpads.

True: I hadn't seen it as general purpose, on my laptops synclient manages the touchpad.

I use this on my dekstop where I tend to accidentally brush against the mouse and the flickering reappearance of the cursor in the corner of my vision tends to induce a micro seizure or some other sort of mildly traumatic neurological event smile


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#1952 2012-10-11 01:03:33

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: Post your handy self made command line utilities

I've crafted this after looking for a quick way to check my available free space of each HDD and the total free space. I would suggest putting it as an alias in you bashrc.

clear;echo "Drive      Size  Used  Avail Use  Mounted on";df -h|grep sd|column -t|sort && df -h --total|cut -c 1-11,17-37|tail -n1

Here's the output from my console

Drive      Size  Used  Avail Use  Mounted on
/dev/sda1  9.9G  5.5G  4.0G  58%  /mnt/chakra
/dev/sda2  922G  779G  143G  85%  /mnt/movies
/dev/sdb1  459G  215G  245G  47%  /mnt/stuff
/dev/sdc1  2.8T  2.3T  501G  83%  /mnt/media
/dev/sdd1  2.8T  2.3T  501G  83%  /mnt/test
/dev/sde1  99M   27M   67M   29%  /boot
/dev/sde3  12G   7.6G  3.7G  68%  /
/dev/sde4  18G   3.0G  14G   18%  /home
total      6.9T  5.5T  1.5T  80%

Offline

#1953 2012-10-11 01:18:59

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

Re: Post your handy self made command line utilities

df -h --total --type=ext{2,3,4}

Add any other filesystem types you use.

Edit: ah, mine isn't sorted.  Still, I think the original could be simplified quite a bit.

df -h --total --type=ext{2,3,4} | sort | awk 'BEGIN { print "Drive\tSize\tUsed\tAvail\tUse\tMount"; } /^[^F]/ { print $0;}'

Sorted.

Last edited by Trilby (2012-10-11 01:23:43)


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

Offline

#1954 2012-10-11 05:42:06

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: Post your handy self made command line utilities

I barely know how to use AWK so thats why I didn't use it. I didn't think the --type flag was necessary since I have a mix of EXT4 and XFS filesystems and it works just fine. Also your headers aren't directly over the columns. That was one of my pet peeves about my original version, hence the use of the echo line instead of df -h|head -n1

Your version doesn't show all my drives either....

 [bran@ra ~]$ echo "Drive      Size  Used  Avail Use  Mounted on";df -h|grep sd|column -t|sort && df -h --total|cut -c 1-11,17-37|tail -n1
Drive      Size  Used  Avail Use  Mounted on
/dev/sda1  9.9G  5.5G  4.0G  58%  /mnt/chakra
/dev/sda2  922G  779G  143G  85%  /mnt/movies
/dev/sdb1  459G  215G  245G  47%  /mnt/stuff
/dev/sdc1  2.8T  2.3T  501G  83%  /mnt/media
/dev/sdd1  2.8T  2.3T  501G  83%  /mnt/test
/dev/sde1  99M   27M   67M   29%  /boot
/dev/sde3  12G   7.6G  3.7G  68%  /
/dev/sde4  18G   3.0G  14G   18%  /home
total      6.9T  5.5T  1.5T  80%
 [bran@ra ~]$ df -h --total --type=ext{2,3,4} | sort | awk 'BEGIN { print "Drive\tSize\tUsed\tAvail\tUse\tMount"; } /^[^F]/ { print $0;}'
Drive   Size    Used    Avail   Use     Mount
/dev/sda1       9.9G  5.5G  4.0G  58% /mnt/chakra
/dev/sdb1       459G  215G  245G  47% /mnt/stuff
/dev/sde1        99M   27M   67M  29% /boot
/dev/sde3        12G  7.6G  3.7G  68% /
/dev/sde4        18G  3.0G   14G  18% /home
total           498G  231G  266G  47%

Last edited by brando56894 (2012-10-11 05:44:03)

Offline

#1955 2012-10-11 05:42:52

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

Re: Post your handy self made command line utilities

Merging with the venerable Command Line Utilities thread...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#1956 2012-10-11 05:44:46

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: Post your handy self made command line utilities

Thanks, I wasn't sure where this belonged.

Offline

#1957 2012-10-14 00:24:29

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

Re: Post your handy self made command line utilities

@brando56894 & @Trilby: try findmnt.
'findmnt --fstab' prints in the order you have in /etc/fstab, so it can be sorted the way you want.

Brief output:

findmnt --fstab -o TARGET,SIZE,AVAIL,USE% -t noswap,notmpfs
TARGET  SIZE AVAIL USE%
/boot  98,8M   73M  21%
/       7,2G    2G  68%
/home  29,1G  1,6G  90%

Regular-sized output:

$ (findmnt --fstab -o SOURCE,SIZE,USED,AVAIL,USE%,TARGET -t noswap,notmpfs && df -h --total | tail -n1) | column -t
SOURCE     SIZE   USED   AVAIL  USE%  TARGET
/dev/sda1  98,8M  20,7M  73M    21%   /boot
/dev/sda3  7,2G   4,9G   2G     68%   /
/dev/sda4  29,1G  26,1G  1,6G   90%   /home
total      46G    36G    7,6G   83%

How to properly (i.e. right-aligned) format the middle columns, is left as an exercise for the reader ;P

Getting 'df -h --total' is less than elegant. Custom headers (or no headers at all) are possible but that one-liner would get even longer.

Offline

#1958 2012-10-16 04:41:34

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: Post your handy self made command line utilities

tmpfile=$(mktemp)
xclip -selection clipboard -o >$tmpfile
cupsfilter -i text/plain $tmpfile 2>/dev/null
rm $tmpfile

Generate pdf from the contents of the clipboard.

Offline

#1959 2012-10-16 12:29:30

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

Re: Post your handy self made command line utilities

To save the tmpfile, something like this might work:

cupsfilter -i text/plain <(clip -selection clipboard -o)

Offline

#1960 2012-10-16 22:29:15

enduser
Member
Registered: 2012-10-04
Posts: 25

Re: Post your handy self made command line utilities

So I'm not sure if this has been posted, but if you install the rfc package (`pacman -S rfc`), you can use this to open an rfc in less:

#!/bin/sh

# display an rfc in `less`

# you may want to install http://www.archlinux.org/packages/community/any/rfc/
# with `pacman -S rfc`

RFC_LOCATION="/usr/share/doc/rfc/txt/"

if [ $# -lt 1 ]; then
	echo "Usage: \`$(basename $0) #\` (where # is the number of the rfc you want to see)"
	exit
fi

rfc="$RFC_LOCATION/rfc$1.txt"

if [ ! -e $rfc ]; then
	echo "rfc '#$1' not found"
	exit
fi

less $rfc

For the lazy (myself included), you can put this in ~/bin with:

curl https://raw.github.com/gist/3902455/ -o ~/bin/rfc && chmod +x ~/bin/rfc

Then just:

rfc 2119

to see rfc #2119 smile

Offline

#1961 2012-10-18 15:35:39

achilleas.k
Member
From: Sol 3
Registered: 2011-10-30
Posts: 117

Re: Post your handy self made command line utilities

I always run htop in my first Yakuake tab so now I just added this to the end of my .bashrc

# make first Yakuake instance run htop (unless htop is already running)
if [[ $( ps -o command $PPID |grep yakuake ) ]];
then
    if [[ ! $(ps -a |grep "\<htop\>" ) ]];
    then
        htop
    fi
fi

Offline

#1962 2012-10-18 15:40:39

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

Re: Post your handy self made command line utilities

I'm not too sure about the logic, but the syntax can be simplied to something like:

ps -o command "$PPID" | grep yakuake && ps -a | grep "\<htop\>" || htop

Offline

#1963 2012-10-18 15:42:42

achilleas.k
Member
From: Sol 3
Registered: 2011-10-30
Posts: 117

Re: Post your handy self made command line utilities

I was absolutely certain someone was going to simplify it (which always happens when I share bash code).
Thanks smile

What do you mean you're not too sure about the logic?

Offline

#1964 2012-10-18 15:44:32

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

Re: Post your handy self made command line utilities

pgrep can help

ps -o command "$PPID" | grep yakuake && pgrep -x htop || htop

I don't know what are you trying to do in

if [[ $( ps -o command $PPID |grep yakuake ) ]];

but maybe you can substitute it for some pgrep too.

Last edited by karol (2012-10-18 15:47:06)

Offline

#1965 2012-10-18 15:51:10

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

Re: Post your handy self made command line utilities

achilleas.k wrote:

What do you mean you're not too sure about the logic?

I mean I didn't stop to think about what it is you're doing.  I just noticed the syntax could be simplified.

Offline

#1966 2012-10-18 15:56:39

achilleas.k
Member
From: Sol 3
Registered: 2011-10-30
Posts: 117

Re: Post your handy self made command line utilities

karol wrote:

I don't know what are you trying to do in

if [[ $( ps -o command $PPID |grep yakuake ) ]];

but maybe you can substitute it for some pgrep too.

Now that I see it, the original version with the "ifs" works as intended. The simplified one-liners don't.
htop should only start if the parent process is Yakuake (the KDE drop-down terminal), not any kind of terminal. The simplified versions start htop in the first terminal that's opened, when htop isn't running.

Offline

#1967 2012-10-18 15:57:19

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

Re: Post your handy self made command line utilities

karol wrote:

pgrep can help

ps -o command "$PPID" | grep yakuake && pgrep -x htop || htop

I don't know what are you trying to do in

if [[ $( ps -o command $PPID |grep yakuake ) ]];

but maybe you can substitute it for some pgrep too.

Maybe this?

pgrep -s "$PPID" -x yakuake

Last edited by steve___ (2012-10-18 15:58:45)

Offline

#1968 2012-10-18 16:01:19

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

Re: Post your handy self made command line utilities

achilleas.k wrote:
karol wrote:

I don't know what are you trying to do in

if [[ $( ps -o command $PPID |grep yakuake ) ]];

but maybe you can substitute it for some pgrep too.

Now that I see it, the original version with the "ifs" works as intended. The simplified one-liners don't.
htop should only start if the parent process is Yakuake (the KDE drop-down terminal), not any kind of terminal. The simplified versions start htop in the first terminal that's opened, when htop isn't running.

oops, try:

ps -o command "$PPID" | grep yakuake && { ps -a | grep "\<htop\>" || htop; }

Offline

#1969 2012-10-18 16:02:16

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

Re: Post your handy self made command line utilities

achilleas.k wrote:

The simplified versions start htop in the first terminal that's opened, when htop isn't running.

Is it possible to open yakuake and run htop, like

xterm -e htop

?

Offline

#1970 2012-10-18 16:04:25

achilleas.k
Member
From: Sol 3
Registered: 2011-10-30
Posts: 117

Re: Post your handy self made command line utilities

You mean have Yakuake run htop directly? Wouldn't that make it run every time I open a new tab in Yakuake?

@steve__: Thanks. The brackets did the trick!

steve___ wrote:

Maybe this?

pgrep -s "$PPID" -x yakuake

pgrep -s "$PPID" always returns nothing.
Should it? pgrep only greps against process name. $PPID is the current process parent PID. It shouldn't be "pgreppable".

Last edited by achilleas.k (2012-10-18 16:12:28)

Offline

#1971 2012-10-18 16:23:22

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

Re: Post your handy self made command line utilities

achilleas.k wrote:

You mean have Yakuake run htop directly? Wouldn't that make it run every time I open a new tab in Yakuake?

I've installed yakuake and even --help-all doesn't tell me how can I do the equivalent of

urxvtc -pe tabbed -e htop

This code opens htop in the first tab of urxvt, you can bind it to an alias or keybinding and start urxvt that way or put it in ~/.xinitrc.

urxvtc -pe tabbed -e htop
exec dwm

Not sure if you want to do it this way.

I've tried the code you said you have in your .bashrc, but it didn't do anything.

Offline

#1972 2012-10-18 16:29:42

achilleas.k
Member
From: Sol 3
Registered: 2011-10-30
Posts: 117

Re: Post your handy self made command line utilities

Well the current state is

ps -o command "$PPID" | grep yakuake > /dev/null && { pgrep -x htop > /dev/null || htop; }

and that works exactly as intended, so I'll keep it there.

Offline

#1973 2012-10-22 09:36:33

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: Post your handy self made command line utilities

Jesus sloccount is verbose...

sloccount $@ 2>/dev/null | grep '(SLOC)' | fex '-1'

Offline

#1974 2012-10-26 21:14:46

owain
Member
Registered: 2009-08-24
Posts: 251

Re: Post your handy self made command line utilities

A little wrapper for get_iplayer, which I have saved as 'iplayernew', to list new programs and use less if necessary:

#!/bin/bash

TMPFILE=$(mktemp)

get_iplayer --refresh --force | grep Added | sed 's/Added: //' > $TMPFILE

LINECOUNT="$(cat $TMPFILE | wc -l)"

if [[ "$LINECOUNT" == "0" ]]; then
    echo "No new programs" 
elif [[ "$LINECOUNT" -lt "$(tput lines)" ]]; then
    cat $TMPFILE
else
    less $TMPFILE
fi

rm $TMPFILE

Last edited by owain (2012-10-26 21:15:21)

Offline

#1975 2012-10-27 05:45:01

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: Post your handy self made command line utilities

This will open the URL for a package:

#!/bin/sh

url=$(eval "expac '%u' $@ || expac -S '%u' $@")

if [ $? -eq 0 ]
then
	xdg-open "$url"
else
	echo 'Package not found.' 1>&2
	exit 1
fi

Last edited by AaronBP (2012-10-27 09:49:49)

Offline

Board footer

Powered by FluxBB