BSDinfo.sh

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

BSDinfo.sh

Unread post by ChefIronBelly » Tue Jun 30, 2015 3:56 pm

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
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: BSDinfo.sh

Unread post by pidsley » Tue Jun 30, 2015 4:21 pm

Thank you Chef.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Tue Jun 30, 2015 5:42 pm

No problem there rough but it wont take to much for me to clean them up.
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: BSDinfo.sh

Unread post by bones » Tue Jun 30, 2015 6:19 pm

Excellent, thanks Chef!

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: BSDinfo.sh

Unread post by wuxmedia » Tue Jun 30, 2015 10:54 pm

sexy scriptage
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: BSDinfo.sh

Unread post by simgin » Wed Jul 01, 2015 8:41 am

Thank you for sharing Chef! Looks like you have some very descent computers :D

cheers
simon
Someone told me that I am delusional, I almost fell off my unicorn.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Wed Jul 01, 2015 4:50 pm

^^ anything sexy came from pidsley ;)

^ Cool

updated OpenBSD script.
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: BSDinfo.sh

Unread post by pidsley » Thu Jul 02, 2015 9:18 pm

[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 :)

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Fri Jul 03, 2015 2:07 am

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.
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: BSDinfo.sh

Unread post by pidsley » Fri Jul 03, 2015 2:15 am

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.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Fri Jul 03, 2015 1:39 pm

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 :)
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Fri Jul 03, 2015 3:04 pm

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).
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: BSDinfo.sh

Unread post by pidsley » Fri Jul 03, 2015 7:05 pm

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.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Fri Jul 03, 2015 7:13 pm

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
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: BSDinfo.sh

Unread post by pidsley » Fri Jul 03, 2015 7:33 pm

^ Thank you, that is interesting.

User avatar
Nili
Haxxor
Posts: 131
Joined: Sat Aug 22, 2015 5:40 pm
Location: $HOME/♫♪
Contact:

Re: BSDinfo.sh

Unread post by Nili » Sun Aug 23, 2015 5:50 pm

I use and found more clean readable than screenfetch. I removed screenfetch after i found this thread :P
Thanks for sharing ChefIronBelly
Devuan/XFCE

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Sun Aug 23, 2015 7:14 pm

All credits to pidsley this was my feeble attempt based on his good work.
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: BSDinfo.sh

Unread post by pidsley » Sun Aug 23, 2015 10:04 pm

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"

User avatar
Nili
Haxxor
Posts: 131
Joined: Sat Aug 22, 2015 5:40 pm
Location: $HOME/♫♪
Contact:

Re: BSDinfo.sh

Unread post by Nili » Mon Aug 24, 2015 10:40 am

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
Devuan/XFCE

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: BSDinfo.sh

Unread post by ChefIronBelly » Mon Aug 24, 2015 6:45 pm

Thank you appreciate it.
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

Post Reply