You are not logged in.

#2976 2017-03-25 15:52:14

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

Re: Post your handy self made command line utilities

Hairyplotter wrote:

There actually is a need for the $DIR variable. If you try to change in to a directory containing spaces with the refinements you posted you get : bash: cd: too many arguments.

No, there is a need to quote the $() or the $DIR.  This is no more true of my invocation than the original.  It will fail with a variable with a space if that variable is not quoted.  I see you did quote the $DIR in yours, so to fix mine:

alias mc='mc -P "/tmp/mc-$USER/mc.pwd.$$" ~ "$PWD"; cd "$(</tmp/mc-$USER/mc.pwd.$$)"; \rm -f /tmp/mc-$USER/mc.pwd.$$'

It is good practice to quote any parameter that comes from somewhere else.  But it just often doesn't occur to me when using `cd` as I'd never tolerate a directory with spaces on my system.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#2977 2017-03-25 16:19:07

Hairyplotter
Member
Registered: 2017-03-25
Posts: 4

Re: Post your handy self made command line utilities

Trilby wrote:
Hairyplotter wrote:

There actually is a need for the $DIR variable. If you try to change in to a directory containing spaces with the refinements you posted you get : bash: cd: too many arguments.

No, there is a need to quote the $() or the $DIR.  This is no more true of my invocation than the original.  It will fail with a variable with a space if that variable is not quoted.  I see you did quote the $DIR in yours, so to fix mine:

alias mc='mc -P "/tmp/mc-$USER/mc.pwd.$$" ~ "$PWD"; cd "$(</tmp/mc-$USER/mc.pwd.$$)"; \rm -f /tmp/mc-$USER/mc.pwd.$$'

It is good practice to quote any parameter that comes from somewhere else.  But it just often doesn't occur to me when using `cd` as I'd never tolerate a directory with spaces on my system.

Thank you, I adopted your suggestion.

Offline

#2978 2017-04-09 14:20:41

nycko
Member
Registered: 2011-08-07
Posts: 15

Re: Post your handy self made command line utilities

A simple Twitch handler in bash, wrapped around streamlink and mpv, that i wrote today. Maybe could be usefull for someone in tty's

3 files to make it simpler to handle. Script automatically handles streamers names from seperate file (ex. twitch-list).

main file (twitch)

#!/bin/bash
. twitch.conf	#configuration file
. twitch.func	#various functions used


#check if any argument has been passed to the script (ex. twitch stream_name stream_quality). If so, run the stream immediately
if [ -n "$1" ]; then
	streamlink --player="mpv --vo=$vo --hwdec=$hwdec" $TWITCH/$1 $2
else
	#main menu, etc.
	d=0
	next=no
	twitchlist
	while [ $d -lt 999 ]; do
		echo "#############################################################################"
		echo -e "$CLEAR 1. $RED Check available streams $CLEAR"
		echo "#############################################################################"
		for (( c=2; c<=$[n-1]; c++))
		do
			echo -e "$CLEAR$c. Run $YELLOW${list[$c]}$CLEAR"
		done
		echo -e "x. Exit"
		
		read d
		num=`echo "$d" | grep -E ^\-?[0-9]+$`
		if [ "$num" != '' ]; then
			next=yes
		fi
		
		clear
		case "$d" in
			"1")	check ;;
			"x")	d=999 ;;
			*)	if [ "$next" = "yes" ] && [ $d -lt $n ]; then
						run ${list[$d]}
					else
						d=0
					fi ;;
		esac
	done
fi

twitch.conf

#!/bin/bash
# Configuration file 

# Path to the streamers list
LIST="/home/user/bin/twitch-list"

# Twitch settings
TWITCH="www.twitch.tv"
TWITCH_QUALITY="medium"

# MPV settings
vo=drm	#video driver (man mpv)
hwdec=vaapi	#hardware decoding method (man mpv)

# Font colors
BLACK="\033[0;30m"
GREEN="\033[0;32m"
BLUE="\033[38;5;75m"
YELLOW="\033[38;5;11m"
RED="\033[38;5;1m"
GRAY="\033[38;5;7m"
ORANGE="\033[38;5;214m"

# Font settings
CLEAR="$(tput sgr0)"	#clears fonts
BOLD="$(tput bold)"

twitch.func

#!/bin/bash

# Parse twitch-list file to array
twitchlist ()
{
	n=2
	while IFS='' read -r line || [[ -n "$line" ]]; do
               list[$n]+=$line
               n=$[n+1]
	done < $LIST
}

# check the status of the streams
check ()
{
	echo -e "$RED Checking available streams: $CLEAR"
	
	i=2
	while [ $i -lt $n ]; do
		echo -e "$YELLOW ${list[$i]} $CLEAR"
		streamlink $TWITCH/${list[$i]}
		i=$[i+1]
	done
}

# run the selected stream
run ()
{
	echo -e "$BLUE Starting $1 stream $CLEAR"
	streamlink --player="mpv --vo=$vo --hwdec=$hwdec" $TWITCH/$1 $TWITCH_QUALITY
}

ex. twitch-list (list of followed/fav streamers)

robinoman
gamingonlinux
wargaming
gogcom

Updated versions always on my GitHub

Last edited by nycko (2017-12-02 19:32:15)

Offline

#2979 2017-04-12 05:59:57

quequotion
Member
From: Oita, Japan
Registered: 2013-07-29
Posts: 814
Website

Re: Post your handy self made command line utilities

bash one liner to watch cpu frequency and various temperatures

watch -n 0 "lscpu | grep 'MHz' && cat /sys/class//hwmon/hwmon[0-9]/temp*_input"

Last edited by quequotion (2017-04-12 12:47:46)

Offline

#2980 2017-04-12 12:43:06

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

Re: Post your handy self made command line utilities

That `[[ true ]] &&` doesn't seem to do anything.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#2981 2017-04-12 12:46:40

quequotion
Member
From: Oita, Japan
Registered: 2013-07-29
Posts: 814
Website

Re: Post your handy self made command line utilities

Trilby wrote:

That `[[ true ]] &&` doesn't seem to do anything.

Yeah, your're right about that. I think there was some reason I put it there, like I was thinking it should work like a while [[ true ]], but it isn't necessary.

Offline

#2982 2017-04-12 13:18:10

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

Re: Post your handy self made command line utilities

If you use a while, you don't need watch:

while :; do clear; lscpu | grep 'MHz'; cat /sys/class//hwmon/hwmon[0-9]/temp*_input; sleep 0.1; done

Watch takes the place of the while, clear, and sleep.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#2983 2017-04-12 17:18:50

brainfucksec
Member
Registered: 2017-03-01
Posts: 40
Website

Re: Post your handy self made command line utilities

One line Pomodoro counter (require 'beep'):

sleep 1500 && notify-send [PAUSE] && beep && echo '[*] pomodoro++' >> pomodoros.txt

Check external IP:

#!/bin/bash

# Program: checkip.sh 
# Description: Simple bash script for check current public IP
# Version: 0.1
# Author: Brainfuck

# define colors
export red=$'\e[0;91m'
export green=$'\e[0;92m'
export blue=$'\e[0;94m'
export white=$'\e[0;97m'
export endc=$'\e[0m'


# curl request: http://ipinfo.io
if ! external_ip="$(curl -s -m 10 ipinfo.io/geo)"; then
	printf "${red}%s${endc}\n" "[FAILED] curl: HTTP request error!"
	exit 1
fi

# print output 
printf "${blue}%s${endc} ${green}%s${endc}\n" "::" "IP Address Details:"

printf "${white}%s${endc}" "$external_ip" \
	| tr -d '"{}' | sed 's/  //g'

--= [ |<!55 ]=--

Offline

#2984 2017-04-12 17:29:31

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Post your handy self made command line utilities

Check external IP...

curl ifconfig.co

smile


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#2985 2017-04-12 17:32:25

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Post your handy self made command line utilities

Command line timer with notification sound and notify-send popup. Set the path to the sound file first (ogg or flac).

#!/bin/bash

# Quick CLI timer. Pass time like '45s', '10m', '1h'
# Requires `paplay` and `notify-send`
# Usage: `timer <time> [reps] [filename]`

snd="/usr/share/sounds/freedesktop/stereo/complete.oga"
if [[ $# == 0 ]]; then
    echo "Usage: timer <time> [reps] [filename]"
    exit 1
fi

# Number of times to play the completed sound (default 2)
reps=${2:-2}
# Filename (.ogg or .flac format)
fn="${3:-$snd}"

a=0
(sleep "$1" && \
    notify-send -t 10000000 " $1 complete ";
    while [[ $a -lt $reps ]];
    do XDG_RUNTIME_DIR=/run/user/$(id -u) paplay --volume=65536 "$fn";
        let "a++";
    done
) &

Last edited by firecat53 (2017-04-12 17:38:54)

Offline

#2986 2017-04-15 00:58:39

hashhar
Member
From: New Delhi, India
Registered: 2017-04-08
Posts: 18
Website

Re: Post your handy self made command line utilities

My own personal mirrolist ranker. I run this after I change network providers or when I'm in a different city or place.

This grew mainly because the Arch Mirror List generator had been acting up. So I wrote my own. Turns out they are thinking of removing it entirely. See https://bbs.archlinux.org/viewtopic.php … 9#p1704409.

Well, any criticism or advice regarding scripting would be appreciated though.

#!/bin/bash

# Customize these parameters {{{
temp_file='/tmp/mirrors.json'
num_mirrors=10

# See https://www.archlinux.org/mirrors/status/ for meaning of these
country='all'      # all, or a name (uses regex matching, so input accordingly)
protocol='all'     # all, http, https, rsync
max_score=100      # lower is better
min_completion=0.9 # as a fraction, 1 is maximum
max_delay=         # a delay value in seconds. Delay in mirroring.
max_latency=       # a value in seconds
max_dev_latency=   # a value in seconds. Std. deviation of latency.
# }}}

# Defaults and Sanitization {{{
[ "$protocol" == 'all' ] && protocol='.*'
[ "$country" == 'all' ] && country='.*'
[ -z "$max_score" ] && max_score=100
[ -z "$min_completion" ] && min_completion=0.9
[ -z "$max_delay" ] && max_delay=86400
[ -z "$max_latency" ] && max_latency=2
[ -z "$max_dev_latency" ] && max_dev_latency=2
# }}}

# Curl and jq pipe {{{
curl https://www.archlinux.org/mirrors/status/json/ |\
    jq ".urls |
        sort_by(.score) |
        .[] |
        select(.country | test(\"$country\")) |
        select(.protocol | test(\"$protocol\")) |
        select(.score != null) |
        select(.score < $max_score) |
        select(.completion_pct > $min_completion) |
        select(.delay < $max_delay) |
        select(.duration_avg < $max_latency ) |
        select(.duration_stddev < $max_dev_latency) |
        { protocol: .protocol, url: .url, country: .country, score: .score }" \
    > "$temp_file"
# }}}

# Extract info to variables {{{
urls=( $(jq -r '.url' "$temp_file") )
scores=( $(jq '.score' "$temp_file") )
# Bash >= 4.0
if (( BASH_VERSINFO >= 4 )); then
    readarray -t countries <<<"$(jq '.country' "$temp_file")"
else
    IFS=$'\n' read -rd '' -a countries <<<"$(jq '.country' "$temp_file")"
fi
count=${#urls[@]}
# }}}

# Write to file {{{
printf '## Generated using hashhars mirrorlist-gen script\n'
printf '## Generated on %s\n' "$(date --rfc-3339=date)"
printf '## Number of mirrors: %s; Country: %s; Protocol: %s; Max Score: %s\n' \
    "$num_mirrors" "$country" "$protocol" "$max_score"
printf '## Min completion percentage: %s; Max mirror delay: %s;\n' \
    "$min_completion" "$max_delay"
printf '## Max avg connection latency: %s; Max std dev of latency: %s\n' \
    "$max_latency" "$max_dev_latency"
printf '\n'
for (( i=0; i < count && i < num_mirrors; ++i )); do
    printf '# %s, Score = %s\nServer = %s$repo/os/$arch\n' \
        "${countries[$i]}" "${scores[$i]}" "${urls[$i]}"
done
# }}}

# vim: et sw=4 tw=80 cc=80 fdm=marker

Offline

#2987 2017-04-15 20:55:45

glyons
Member
From: Europa
Registered: 2016-10-14
Posts: 37

Re: Post your handy self made command line utilities

hashhar wrote:

My own personal mirrolist ranker. I run this after I change network providers or when I'm in a different city or place.

This grew mainly because the Arch Mirror List generator had been acting up. So I wrote my own. Turns out they are thinking of removing it entirely. See https://bbs.archlinux.org/viewtopic.php … 9#p1704409.

Well, any criticism or advice regarding scripting would be appreciated though.
.....

Looks good and it works!

Just for your information  there is a package called reflector

Reflector
Reflector is a script which can retrieve the latest mirror list from the MirrorStatus page, filter the most up-to-date mirrors, sort them by speed and overwrite the file /etc/pacman.d/mirrorlist.
https://wiki.archlinux.org/index.php/reflector

Offline

#2988 2017-04-16 00:03:19

hashhar
Member
From: New Delhi, India
Registered: 2017-04-08
Posts: 18
Website

Re: Post your handy self made command line utilities

Just for your information  there is a package called reflector

Reflector
Reflector is a script which can retrieve the latest mirror list from the MirrorStatus page, filter the most up-to-date mirrors, sort them by speed and overwrite the file /etc/pacman.d/mirrorlist.
https://wiki.archlinux.org/index.php/reflector

Thanks for the link. I found reflector too. But I built this mainly as an excuse to get my hands dirty with some jq.

Also, please don't put this in a cron job. The server that generates the mirrorlist status is quite loaded I guess and we don't want that service to be taken away. I personally run this only when I am traveling or change network providers.

Offline

#2989 2017-04-19 22:49:07

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 675

Re: Post your handy self made command line utilities

I use pacaur, have more than one Arch machine at home, and have a slow internet connection so I created this program to sync Arch package and AUR updates between my machines. I use it every day and am quite happy with it so I have shared it in the AUR.

Offline

#2990 2017-04-20 07:35:51

Sachiko
Member
Registered: 2016-07-01
Posts: 17

Re: Post your handy self made command line utilities

While I know this next one is a bit indifferent for most as one usually uses just a normal xinitrc or a display manager, I don't. I like to make things to help myself.

wmchooser

Allows me to choose any of the listed window managers or desktop environments to use upon issuance of startx(which my xinitrc contains the command to execute the following script)

#!/bin/bash

session=$(zenity --width=228\
           --height=384\
           --list\
           --title "SelectWm"\
            --text "Select Window Manager/Desktop Environment"\
            --column ""\
            "2bwm"\
            "9wm"\
            "adwm"\
            "aewm"\
            "afterstep"\
            "alopex"\
            "antico"\
            "antiwm"\
            "awesome"\
            "barewm"\
            "blackbox"\
            "bspwm"\
            "bubbleswm"\
            "budgie"\
            "catwm"\
            "cinnamon"\
            "ctwm"\
            "cwm"\
            "deepin"\
            "dwin"\
            "dwm"\
            "echinus"\
            "ede"\
            "eggwm"\
            "enlightenment"\
            "etwm"\
            "evilwm"\
            "flatman"\
            "fluxbox"\
            "foowm"\
            "frankenwm"\
            "fvwm"\
            "glass"\
            "glass-wm"\
            "gnome"\
            "gnome-classic"\
            "goomwwm"\
            "heliwm"\
            "herbstluftwm"\
            "howm"\
            "i3wm"\
            "icewm"\
            "ion3"\
            "jbwm"\
            "jwm"\
            "karmen"\
            "kde"\
            "larswm"\
            "lumina"\
            "lxde"\
            "lxqt"\
            "lwm"\
            "mantiswm"\
            "mate"\
            "mcwm"\
            "mini"\
            "mlvwm"\
            "moksha"\
            "monsterwm"\
            "notion"\
            "olvwm"\
            "openbox"\
            "pantheon"\
            "pawm"\
            "pekwm"\
            "plwm"\
            "qtile"\
            "ratpoison"\
            "sawfish"\
            "spectrwm"\
            "steam"\
            "stumpwm"\
            "subtle"\
            "sugar"\
            "swm"\
            "tinywm"\
            "trinity"\
            "tritium"\
            "twm"\
            "ude"\
            "unity"\
            "velox"\
            "vtwm"\
            "vwm"\
            "waimea"\
            "windowchef"\
            "windwm"\
            "wingo"\
            "wmaker"\
            "wmfs"\
            "wmii"\
            "wmx"\
            "wm2"\
            "wtftw"\
            "wumwum"\
            "xdwm"\
            "xfce4"\
            "xmonad"\
            "yeahwm"\
                )


case $session in
    2bwm              ) exec 2bwm;;
    9wm               ) exec 9wm;;
    adwm              ) exec adwm;;
    aewm              ) exec aewm;;
    afterstep         ) exec afterstep;;
    alopex            ) exec alopex;;
    antico            ) exec antico;;
    antiwm            ) exec antiwm;;
    awesome           ) exec awesome;;
    barewm            ) exec barewm;;
    blackbox          ) exec blackbox;;
    bspwm             ) exec bspwm;;
    bubbleswm         ) exec bubbleswm;;
    budgie            ) exec budgie-desktop;;
    catwm             ) exec catwm;;
    cinnamon          ) exec cinnamon-session;;
    ctwm              ) exec ctwm;;
    cwm               ) exec cwm;;
    deepin            ) exec startdde;;
    dwin              ) exec dwin;;
    dwm               ) exec dwm;;
    echinus	      ) exec echinus;;
    ede               ) exec startede;;
    eggwm             ) exec eggwm;;
    enlightenment     ) exec enlightenment_start;;
    etwm              ) exec etwm;;
    evilwm            ) exec evilwm;;
    flatman           ) exec flatman;;
    fluxbox           ) exec startfluxbox;;
    foowm             ) exec foowm;;
    frankenwm         ) exec frankenwm;;
    fvwm              ) exec fvwm;;
    glass             ) exec glass;;
    glass-wm          ) exec glass-wm;;
    goomwwm           ) exec goomwwm;;
    gnome             ) exec gnome-session;;
    gnome-classic     ) exec gnome-session --session=gnome-classic;;
    heliwm            ) exec heliwm;;
    herbstluftwm      ) exec herbstluftwm;;
    howm              ) exec howm;;
    i3wm              ) exec i3;;
    ion3              ) exec ion3;;
    icewm             ) exec icewm-session;;
    jbwm              ) exec jbwm;;
    jwm               ) exec jwm;;
    karmen            ) exec karmen;;
    kde               ) exec startkde;;
    larswm            ) exec larswm;;
    lumina            ) exec start-lumina-desktop;;
    lxde	      ) exec lxsession;;
    lxqt              ) exec startlxqt;;
    lwm               ) exec lwm;;
    mantiswm          ) exec mantis;;
    matwm2            ) exec matwm2;;
    mate              ) exec mate-session;;
    mcwm              ) exec mcwm;;
    mini              ) exec mini;;
    mlvwm             ) exec mlvwm;;
    moksha            ) exec enlightenment_start;;
    monsterwm         ) exec monsterwm;;
    notion            ) exec notion;;
    olvwm             ) exec olvwm;;
    openbox           ) exec openbox-session;;
    pantheon          ) gsettings-data-convert &
                        xdg-user-dirs-gtk-update &
                        /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
                        /usr/lib/gnome-settings-daemon/gnome-settings-daemon &
                        /usr/lib/gnome-user-share/gnome-user-share &
                        eval $(gnome-keyring-daemon --start --components=pkcs11,secrets,ssh,gpg)
                        export GNOME_KEYRING_CONTROL GNOME_KEYRING_PID GPG_AGENT_INFO SSH_AUTH_SOCK
                        exec cerbere;;
    pawm              ) exec pawm;;
    pekwm             ) exec pekwm;;
    plwm              ) exec plwm;;
    qtile             ) exec qtile;;
    ratpoison         ) exec ratpoison;;
    sawfish           ) exec sawfish;;
    spectrwm          ) exec spectrwm;;
    steam	      ) exec steam-de;;
    stumpwm           ) exec stumpwm;;
    subtle            ) exec subtle;;
    sugar             ) exec sugar;;
    swm               ) exec swm;;
    tinywm            ) exec tinywm;;
    trinity           ) exec starttde;;
    tritium           ) exec tritium;;
    twm               ) exec twm;;
    ude		      ) exec uwm;;
    unity             ) exec unity;;
    velox             ) exec velox;;
    vtwm              ) exec vtwm;;
    vwm               ) exec vwm;;
    waimea            ) exec waimea;;
    windowchef        ) exec windowchef;;
    windwm	      ) exec wind;;
    wingo             ) exec wingo;;
    wmaker            ) exec wmaker;;
    wmfs              ) exec wmfs;;
    wmii              ) exec wmii;;
    wmx               ) exec wmx;;
    wm2               ) exec wm2;;
    wtftw             ) exec wtftw;;
    wumwum            ) exec wumwum;;
    xdwm              ) exec xdwm;;
    xfce4             ) exec startxfce4;;
    xmonad            ) exec xmonad;;
    yeahwm            ) exec yeahwm;;
esac

Yes, I know it's a mess to have every window manager and desktop environment listed all the time, however, I am currently unsure of how to make entries in a zenity script conditional or if it's even possible, but this was just something I did out of boredom and as an exercise on the structure and usage of the case function.

Last edited by Sachiko (2017-04-20 07:59:30)

Offline

#2991 2017-04-20 11:03:47

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

Re: Post your handy self made command line utilities

You could trim that script down to about half it's length while also making it much easier to revise/add-to by listing each wm only once in an associative array rather than listing each in both the zenity command and the case statement:

declare -A wms=(
   # ...
   [xdwm]="exec xdwm"
   [xfce4]="exec startxfce4"
   [xmonad]="exec xmonad"
   [yeahwm]="exec yeahwm"
)

session=$(zenity --width=228 --height=384 --list --title "SelectWm" \
      --text "Select Window Manager/Desktop Environment" --column "" \
      $(printf "\"%s\" " "${!wms[@]}"))

${wms[$session]}

You can also then simply comment or uncomment lines of the associative array to include/exclude some of the options.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#2992 2017-04-20 11:16:30

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

Re: Post your handy self made command line utilities

This is why we always split data from logic. The names of those desktop environments are data, they don't belong into the script, they belong into a config file or in a routine, that checks for existing desktops. Display managers check for existing desktop files in a specific path. Your script doesn't catch errors. Do you always have those options installed?

Another pet peeve of mine: You store the click's result in a variable and read that variable later. I recommend you familiarize yourself with procedures/functions in bash to avoid the otherwise inevitable bad style you'll have to get rid of later, should you decide to step up your game at some point.

Offline

#2993 2017-04-20 13:34:43

Sachiko
Member
Registered: 2016-07-01
Posts: 17

Re: Post your handy self made command line utilities

Trilby wrote:

You could trim that script down to about half it's length while also making it much easier to revise/add-to by listing each wm only once in an associative array rather than listing each in both the zenity command and the case statement:

...

You can also then simply comment or uncomment lines of the associative array to include/exclude some of the options.

I appreciate the nudge in a more convenient direction as I took what you said and broke it down like Awebb said into data(wm choices, stored as the associative array in ~/.wmrc and sourced in the main script) and logic(the zenity portion).

I was looking into using the .desktop files located in /usr/share/xsessions to do a better job of listing and running the window managers and desktop environments as to minimize the tediousness of this. However, what I and possibly others have noticed is not all window managers add those files which puts that idea to a grinding halt.

EDIT:


wmchooser

#!/bin/bash

source $HOME/.wmrc

session=$(zenity --width=228 --height=384 --list --title "SelectWm" \
      --text "Select Window Manager/Desktop Environment" --column "" \
      $(printf "%s" "${!wms[*]}")
      )

${wms[$session]}

.wmrc

#!/bin/bash

typeset -A wms=(
#            [2bwm]="exec 2bwm"
#            [9wm]="exec 9wm"
#            [adwm]="exec adwm"
#            [aewm]="exec aewm"
#            [afterstep]="exec afterstep"
#            [alopex]="exec alopex"
#            [antico]="exec antico"
#            [antiwm]="exec antiwm"
             [awesome]="exec awesome"
#            [barewm]="exec barewm"
#            [blackbox]="exec blackbox"
#            [bspwm]="exec bspwm"
#            [bubbleswm]="exec bubbleswm"
#            [budgie]="exec budgie-desktop"
#            [catwm]="exec catwm"
#            [cinnamon]="exec cinnamon-session"
#            [ctwm]="exec ctwm"
#            [cwm]="exec cwm"
#            [deepin]="exec startdde"
#            [dwin]="exec dwin"
             [dwm]="exec dwm"
#            [echinus]="exec echinus"
#            [ede]="exec ede"
#            [eggwm]="exec eggwm"
#            [enlightenment]="exec enlightenment_start"
#            [etwm]="exec etwm"
#            [evilwm]="exec evilwm"
#            [flatman]="exec flatman"
#            [fluxbox]="exec startfluxbox"
#            [foowm]="exec foowm"
#            [frankenwm]="exec frankenwm"
#            [fvwm]="exec fvwm"
#            [glass]="exec glass"
#            [glass-wm]="exec glass-wm"
#            [gnome]="exec gnome-session"
#            [gnome-classic]="exec gnome-session --session=gnome-classic"
#            [goomwwm]="exec goomwwm"
#            [heliwm]="exec heliwm"
#            [herbstluftwm]="exec herbstluftwm"
#            [howm]="exec howm"
#            [i3wm]="exec i3"
#            [icewm]="exec icewm"
#            [ion3]="exec ion3"
#            [jbwm]="exec jbwm"
#            [jwm]="exec jwm"
#            [karmen]="exec karmen"
#            [kde]="exec startkde"
#            [larswm]="exec larswm"
#            [lumina]="exec start-lumina-desktop"
#            [lxde]="exec lxsession"
#            [lxqt]="exec startlxqt"
#            [lwm]="exec lwm"
#            [mantiswm]="exec mantis"
#            [mate]="exec mate-session"
#            [mcwm]="exec mcwm"
#            [mini]="exec mini"
#            [mlvwm]="exec mlvwm"
#            [moksha]="exec enlightenment_start"
#            [monsterwm]="exec monsterwm"
#            [notion]="exec notion"
#            [olvwm]="exec olvwm"
#            [openbox]="exec openbox-session"
#            [pantheon]="exec cerbere"
#            [pawm]="exec pawm"
#            [pekwm]="exec pekwm"
#            [plwm]="exec plwm"
#            [qtile]="exec qtile"
#            [ratpoison]="exec ratpoison"
#            [sawfish]="exec sawfish"
#            [spectrwm]="exec spectrwm"
#            [steam]="exec steam-de"
#            [stumpwm]="exec stumpwm"
#            [subtle]="exec subtle"
#            [sugar]="exec sugar"
#            [swm]="exec swm"
#            [tinywm]="exec tinywm"
#            [trinity]="exec starttde"
#            [tritium]="exec trinity"
#            [twm]="exec twm"
#            [ude]="exec uwm"
#            [unity]="exec unity"
#            [velox]="exec velox"
#            [vtwm]="exec vtwm"
#            [vwm]="exec vwm"
#            [waimea]="exec waimea"
#            [windowchef]="exec windowchef"
#            [windwm]="exec wind"
#            [wingo]="exec wingo"
#            [wmaker]="exec wmaker"
#            [wmfs]="exec wmfs"
#            [wmii]="exec wmii"
#            [wmx]="exec wmx"
#            [wm2]="exec wm2"
#            [wtftw]="exec wtftw"
#            [wumwum]="exec wumwum"
#            [xdwm]="exec xdwm"
#            [xfce4]="exec startxfce4"
#            [xmonad]="exec xmonad"
#            [yeahwm]="exec yeahwm"
	)

And the ones I personally have installed atm are uncommented in the above .wmrc

Last edited by Sachiko (2017-04-21 06:07:06)

Offline

#2994 2017-05-08 12:53:44

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

Re: Post your handy self made command line utilities

Something i ever wanted to do, quite simple, named executor.sh

#!/bin/bash
SCRIPTDIR=${0%/*}
cd $SCRIPTDIR

chmod 700 .
chown -R `whoami` .

mkdir executed &>/dev/null
rm ./execme.sh

while true ; do
    touch ./execme.sh
    chmod 700 .
    chown -R `whoami` .
    inotifywait -e modify ./execme.sh
    . ./execme.sh &
    mv ./execme.sh executed/
done

Basically, $user is supposed to start the script as he logs in in a graphical environment.
Then the same user - or root, that's the scope - can write commands into execme.sh and they will be executed in the graphical environment of $user (as $user)
I know systemd can acheive something similar, but this one works too and imho is simpler.

I can now use GUI cron commands smile

Last edited by kokoko3k (2017-05-08 12:59:20)


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

Offline

#2995 2017-05-08 14:50:48

IrvineHimself
Member
From: Scotland
Registered: 2016-08-21
Posts: 275

Re: Post your handy self made command line utilities

I have been working on a project which, (while probably of  little practical use,) many people may find interesting.  Basically, it analyses the output from ‘arch-audit’ and prepares a formatted, easy to read report on how the underlying package advisories affect your top-level applications.

You can find it here on GitHub, along with a fuller description and screenshots.

Note: If you are of a nervous disposition, (or prone to panic attacks,) you might want to give  this a miss. Some of the base package advisories are inherited  by a great many applications.

Other than curiosity about the system wide effect of the advisories, my main motivation was to help me master writing bash shells and get to grips with Git. So feedback is welcome.

Irvine


Et voilà, elle arrive. La pièce, le sous, peut-être qu'il arrive avec vous!

Offline

#2996 2017-05-08 22:23:28

escondida
Package Maintainer (PM)
Registered: 2008-04-03
Posts: 157

Re: Post your handy self made command line utilities

# Some preliminary steps to make Chromium usable

A couple of days ago, I reluctantly switched to Chromium, because Mozilla is making it harder and harder to keep conkeror running well.

One of the first things I noticed is that it is nearly impossible to make Chromium cooperate with your system at large. A primitive beginning of a solution was to override /usr/bin/xdg-open (I can't be bothered; I just want to send things through the plan9 plumber (general-purpose launcher and message sender)) with ~/local/bin/xdg-open:

#!/usr/bin/env rc

plumb -s xdg-open `{echo $1 | sed 's,^plumb://,,'}

If it's sent anything beginning with "plumb://", it will remove that prefix and send on the rest; otherwise, it'll simply run the plumber on its argument. Why the prefix? Because one of the only ways to convince Chromium to communicate with any other program is to make it think it's looking at an Internet protocol it doesn't know how to handle. When it encounters such a protocol, it passes it on to xdg-open. This tidbit, coupled with an extension called Redirector (note: there may well be better options for redirection out there; this is the first thing I found for the purpose) allows me to fool Chromium into thinking arbitrary addresses actually begin with plumb://. For instance, to open YouTube videos in mpv:

^https://(www\.)?youtube\.com/watch\?v=.*$
→ plumb://$& # The extension's regexps use $ instead of \, for some reason
⇒ plumb://https://www.youtube.com/watch?v=some_video_here

Oddly, this particular redirection only seems to work when opening the page in a new tab; I have no idea why.

Obviously, this is a crude and limited approach; I hope to figure out a better solution at some point, ideally one that doesn't involve setting up special rules for everything I want to see outside of the browser. I also hope to figure out some way of easily opening a text area in, well, a text editor (besides just writing it in the text editor and pasting it in).

I also noticed that Chromium creates ~/.pki. After removing conkeror (good night, sweet browser, and flights of angle brackets sing thee to thy rest) and firefox, this ~/.pki is my very last dotfile; everything else either uses a sane configuration location by default or can be wrapped. Since Chromium doesn't seem to use $HOME for anything *useful*, I also wrapped it in a tiny launcher script (replacing Arch's launcher script) that fools it into thinking $HOME is ~/local/cfg/chromium; now all of its clutter goes there.

Last edited by escondida (2017-05-08 22:25:03)

Offline

#2997 2017-05-09 14:14:04

Aerial Boundaries
Member
Registered: 2015-05-15
Posts: 26

Re: Post your handy self made command line utilities

Like killall, but it restarts them with the original args:

#!/bin/bash                                                                                    
                                                                               
pgrep -a $1 | while read -r line; do                                           
        kill $(cut -d' ' -f1 <<< $line)                                        
        eval nohup $(cut -d' ' -f2- <<< $line) >/dev/null 2>&1 &               
done
escondida wrote:

I also hope to figure out some way of easily opening a text area in, well, a text editor (besides just writing it in the text editor and pasting it in.

If you're willing to use it, the cVim addon has this feature.

Offline

#2998 2017-05-09 19:16:16

escondida
Package Maintainer (PM)
Registered: 2008-04-03
Posts: 157

Re: Post your handy self made command line utilities

Aerial Boundaries wrote:

Like killall, but it restarts them with the original args:

#!/bin/bash                                                                                    
                                                                               
pgrep -a $1 | while read -r line; do                                           
        kill $(cut -d' ' -f1 <<< $line)                                        
        eval nohup $(cut -d' ' -f2- <<< $line) >/dev/null 2>&1 &               
done

You may be interested to know that /usr/bin/kill can actually kill processes by name, but some shells, such as bash, "helpfully" provide their own, inferior implementation for hysterical raisins. "enable -n kill" will disable bash's built-in function.

escondida wrote:

I also hope to figure out some way of easily opening a text area in, well, a text editor (besides just writing it in the text editor and pasting it in.

If you're willing to use it, the cVim addon has this feature.

Thanks for the tip. I don't think I'll be using cVim, but I will *definitely* be examining it for more information. Much appreciated!

Offline

#2999 2017-05-12 04:48:08

LeoMingo
Member
Registered: 2017-05-07
Posts: 20

Re: Post your handy self made command line utilities

Since chromium does not work under root environment by default, here is a quick script:

 #!/bin/sh
 CWD='pwd' 
 COMMAND='chromium --no-sandbox --user-data-dir'
 if [[ $# == 0 ]]; then
     $COMMAND > /dev/null
 else
     $COMMAND "$@"
 fi

Name it chro or something.

Last edited by LeoMingo (2017-05-12 04:50:17)

Offline

#3000 2017-05-12 04:56:41

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

Re: Post your handy self made command line utilities

LeoMingo wrote:

Since chromium does not work under root environment by default


Why would you think running, of all things, a web browser as root would be a good idea?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB