Page 1 of 1

BSDinfo.sh

Posted: Tue Jun 30, 2015 3:56 pm
by ChefIronBelly
Per Mr Pidsley's request here is the BSDinfo scripts. My hackery should not in anyway tarnish his good name. Limited testing and checking for malformed files.
Comes under the 'It is what it is' license.

ChefIronBelly/BSD-scripts
fbsd.jpg
nbsdinfo.jpg
obsdinfo.jpg
enjoy

Re: BSDinfo.sh

Posted: Tue Jun 30, 2015 4:21 pm
by pidsley
Thank you Chef.

Re: BSDinfo.sh

Posted: Tue Jun 30, 2015 5:42 pm
by ChefIronBelly
No problem there rough but it wont take to much for me to clean them up.

Re: BSDinfo.sh

Posted: Tue Jun 30, 2015 6:19 pm
by bones
Excellent, thanks Chef!

Re: BSDinfo.sh

Posted: Tue Jun 30, 2015 10:54 pm
by wuxmedia
sexy scriptage

Re: BSDinfo.sh

Posted: Wed Jul 01, 2015 8:41 am
by simgin
Thank you for sharing Chef! Looks like you have some very descent computers :D

cheers
simon

Re: BSDinfo.sh

Posted: Wed Jul 01, 2015 4:50 pm
by ChefIronBelly
^^ anything sexy came from pidsley ;)

^ Cool

updated OpenBSD script.

Re: BSDinfo.sh

Posted: Thu Jul 02, 2015 9:18 pm
by pidsley
[please pardon the script feedback -- I mean no offense]

Personally, I'd lose the code where you convert the wm name to mixed case, but that's just my preference. At least make it a function, since you use it in two different places. You could also make two arrays, one for pid searching and the other mixed case, then use the index of the found pid to index into the second array, like this:

Code: Select all

wms=( 2bwm 2wm 9wm aewm afterstep ahwm alopex amiwm antiwm awesome ratpoison blackbox bspwm catwm clfswm ctwm cwm dminiwm dragonflywm dwm echinus )
wmnames=( 2bwm 2wm 9wm Aewm Afterstep Ahwm Alopex AmiWM AntiWM AwesomeWM Ratpoison BlackBox Bspwm Catwm Clfswm Ctwm cwm DminiWM DragonflyWM DWM Echinus )

print-wm() {   
    for (( i=0; i<${#wms[*]}; i++ )); do    # loop through wm array by index
        pid=$(pgrep -x -u $USER ${wms[i]})  # if found, this wm has running process
        if [[ "$pid" ]]; then
            color-echo WM ${wmnames[$i]}    # index into wmnames array
            break
        fi
    done
}
This assumes that there is a one-to-one correspondence between the two arrays and that they are in the correct order.

This would also be a perfect case for an associative array, like this:

Code: Select all

declare -A wms=( [9wm]=9WM [ratpoison]=Ratpoison [blackbox]=BlackBox ) # small array for test purposes, expand as necessary

print-wm() {
    for wm in ${!wms[@]}; do          # loop through wm array by key
        pid=$(pgrep -x -u $USER $wm)  # if found, this wm key has running process
        if [[ "$pid" ]]; then
            color-echo WM ${wms[$wm]} # get the value for this key from the associative array
            break
        fi
    done
}
(thanks for making me finally learn how to use associative arrays in bash :)

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 2:07 am
by ChefIronBelly
That stuff was lifted straight from screenfetch. I may have tweaked a bit if it didn't work or tried to simplify per distro but most of it did work.

Anyway thanks for the feedback I will certainly be taking a close look at your suggestion.

Thank you

EDIT: I think the whole mixed array bit was used to cover all the linux and BSD iterations. I think since now they are specific per distro you are correct that bit can go. I will dig in tomorrow morning with a freshly caffeinated head to much sun today.

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 2:15 am
by pidsley
Yes, I recognized the screenfetch code :) Those big case and if/elif blocks just bug me, but "it works pidsley, so stfu" is certainly a valid response.

No problem if you don't want to implement any of this -- it's only ideas and an excuse for me to try some things I haven't done before.

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 1:39 pm
by ChefIronBelly
pidsley wrote:"it works pidsley, so stfu" is certainly a valid response.
Never... I agree I hate there code it was a matter of time vs effort when I was going thru the BSD thing. I really thought it would be a use one and done type usage. But as it turns out I really like them and have been using more and more.

I plan on implementing your suggestion and working my way down thru that code. Im sure I will have some things to bounce off you soon.

Happy 4th :)

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 3:04 pm
by ChefIronBelly
I ended up using this... do you recognize it :D

pgrep flags are working a little different the -x -u never found the pid adding -a worked for FreeBSD. -x -u worked for NetBSD, OpenBSD.

Code: Select all

wms=( 2bwm 2wm 9wm aewm afterstep ahwm alopex amiwm antiwm awesome blackbox bspwm catwm clfswm ctwm cwm dminiwm dragonflywm dwm echinus \
    euclid-wm evilpoison evilwm fluxbox flwm fvwm-crystal goomwwm hcwm herbstluftwm i3 icewm jwm karmen larswm lwm matwm2 mcwm monsterwm \
    musca notion nwm olwm openbox oroborus pekwm ratpoison sapphire sawfish sscrotwm sithwm smallwm snapwm spectrwm stumpwm subtle tfwm tinywm tritium twm \
    uwm vtwm w9wm weewm wind windowlab wm2 wmaker wmfs wmii wmx xfwm4 xmonad xoat yeahwm )

Code: Select all

print-wm() {
    for wm in ${wms[@]}; do          # pgrep through wmname array
        pid=$(pgrep -a -x -u $USER $wm)
        if [[ "$pid" ]]; then
            color-echo 'WM' $wm
	        break
        fi
    done
}
-a Include process ancestors in the match list. By default, the
current pgrep or pkill process and all of its ancestors are
excluded (unless -v is used).

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 7:05 pm
by pidsley
Nice. I like having the wm name all lower case, and the code is much simpler now.

It does feel like I've seen that code somewhere before... :)

The differences in the BSD coreutils are part of what always puts me off using BSD. They are just different enough to be annoying.

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 7:13 pm
by ChefIronBelly
One fun fact I learned today was that the p* tools pkill pgrep etc came from Solaris 7 > BSD.

https://en.wikipedia.org/wiki/Pgrep

Re: BSDinfo.sh

Posted: Fri Jul 03, 2015 7:33 pm
by pidsley
^ Thank you, that is interesting.

Re: BSDinfo.sh

Posted: Sun Aug 23, 2015 5:50 pm
by Nili
I use and found more clean readable than screenfetch. I removed screenfetch after i found this thread :P
Thanks for sharing ChefIronBelly

Re: BSDinfo.sh

Posted: Sun Aug 23, 2015 7:14 pm
by ChefIronBelly
All credits to pidsley this was my feeble attempt based on his good work.

Re: BSDinfo.sh

Posted: Sun Aug 23, 2015 10:04 pm
by pidsley
Nili wrote:I use and found more clean readable than screenfetch. I removed screenfetch after i found this thread :P
Thanks for sharing ChefIronBelly
nili, are you using BSD or a BBQ spin? If you are using a BBQ spin you probably already have the original script. The BBQ version is called "env-info"

Re: BSDinfo.sh

Posted: Mon Aug 24, 2015 10:40 am
by Nili
pidsley wrote:nili, are you using BSD or a BBQ spin? If you are using a BBQ spin you probably already have the original script. The BBQ version is called "env-info"
I' m using simple netinst Debian 8.1 with your env-info a few (scrots) include env-info

So thanks for making it, as i said removed screenfetch in favor of env-info script - i'm happy :P
ChefIronBelly wrote:All credits to pidsley this was my feeble attempt based on his good work.
I congratulated you for your editing effort, but i'm using pidsley's code for some time :D

Re: BSDinfo.sh

Posted: Mon Aug 24, 2015 6:45 pm
by ChefIronBelly
Thank you appreciate it.