You are not logged in.

#3501 2021-01-23 02:28:55

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 997
Website

Re: Post your handy self made command line utilities

Automount USB sticks using udev rule (for udev running outside of systemd namespace).

Yes I know this is a bad idea and that I "should" be using udisks. Sue me tongue

ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ATTR{removable}=="1", RUN{program}+="/home/<username>/scripts/automount.sh $devnode"
#!/bin/bash
set -uo pipefail

_mount() {
    local -r _user="$(who | awk '{print $1}')"
    local -r _dir="/mnt/$(basename "${1}")"
    local -ir _uid="$(id -u "${_user}")"
    local -ir _gid="$(id -g "${_user}")"
    install -m 755 -g "${_user}" -o "${_user}" -d "${_dir}"
    mount -o uid="${_uid}",gid="${_gid}" "${1}" "${_dir}"
}

_enum() {
    local -a _partitions=()
    mapfile -t _partitions <<< "$(lsblk -o name -lnp "${1}")"
    for part in "${_partitions[@]}"
    do
        if [[ "${part}" != "${1}" ]]
        then
            _mount "${part}"
        fi
    done
}

( _enum "${1}" ) &

Last edited by karabaja4 (2021-01-24 02:44:48)

Offline

#3502 2021-01-23 06:20:16

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: Post your handy self made command line utilities

Awebb wrote:

Based on some recommendations google spit out, here is my bash script using youtube-dl that downloads Audio from Youtube and splits it into one file per video chapter.

#!/bin/bash
url="$1"
basename=$(youtube-dl --dump-single-json "$url" | jq .title | tr -cd '[:alnum:]')
downloads="~/Downloads/_youtube-dl/"
mkdir -p "$downloads"/"$basename"
cd "$downloads"/"$basename"
youtube-dl --write-info-json -x --audio-format mp3 -o "$basename.%(ext)s" "$url"
jq '.chapters[] | .start_time,.end_time-.start_time,.title ' < $basename.info.json | xargs -n3 -d'\n' | awk '{print NR" "$s}' > chapters
while read -r track start duration title; do
        title=${title//\"/}
        ffmpeg -loglevel warning -nostdin -y -ss "$start" -t "$duration" -i "$basename.mp3" -codec:a copy "$track - $title.mp3"
done < chapters

It doesn't clean up after itself and probably doesn't handle errors very well.

 pacman -S cuetools shntool

shnsplit -f "$1".cue -t %n-%t -o flac "$1".flac
cuetag.sh "$1".cue [0-9]*.flac

It shall work with mp3 too ( I have only used with flac)

Offline

#3503 2021-02-02 21:46:42

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,794
Website

Re: Post your handy self made command line utilities

Suspend my machine when I shutdown my Bluetooth headset. Quick and dirty but whatever...

// build main.go with
// go build -o bsus main.go
package main

import (
	"bytes"
	"os/exec"
	"time"
)

func main() {
	var out []byte
	var lines int
	for {
		out, _ = exec.Command("pactl", "list", "cards", "short").Output()
		lines = bytes.Count(out, []byte{'\n'})
		if lines < 2 {
			exec.Command("systemctl", "suspend").Run()
			return
		}
		time.Sleep(time.Second * 5)
	}
}

https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#3504 2021-02-04 05:43:09

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: Post your handy self made command line utilities

record selected window+audio with ffmpeg

#!/bin/bash
slop=$(slop -f "%x %y %w %h %g %i") || exit 1
read -r X Y W H G ID < <(echo $slop)

ffmpeg -f x11grab -framerate 15 -draw_mouse 0 \
    -s "$W"x"$H" -i :0.0+$X,$Y \
    -f pulse -ar 44100 -ac 2 -i 0 -b 300k /tmp/$(date +%d%m%Y_%H%M%S).mp4

Offline

#3505 2021-02-04 10:59:01

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

Re: Post your handy self made command line utilities

Does it really select a window or does it record the selected area?

Offline

#3506 2021-02-04 11:42:09

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: Post your handy self made command line utilities

Both can be done. Click to select, or draw a rectangle to select area. slop gets the coordinates and that is fed to ffmpeg.

EDIT: Oh,, I got it. It selects area of window when window is clicked, But you shall not move the window during recording. AFAIK ffmpeg supports window grabing in Windows using gdigrab but in linux x11grab only supports area selection.

Last edited by Docbroke (2021-02-04 11:51:26)

Offline

#3507 2021-02-04 14:27:03

xyproto
Package Maintainer (PM)
From: Oslo
Registered: 2011-01-11
Posts: 43
Website

Re: Post your handy self made command line utilities

Be reminded of lunch, directly on the prompt: https://github.com/xyproto/sealion

Last edited by xyproto (2021-02-09 21:11:30)

Offline

#3508 2021-02-05 01:59:45

CarbonChauvinist
Member
Registered: 2012-06-16
Posts: 412
Website

Re: Post your handy self made command line utilities

Worked on correcting a lot of my earlier fumbling to something, humbly ...improved? ...relatively at least

This just checks all my "vcs" packages for updates using the incredible aurutils tools.. any fixes are very welcome

vcs-sync () {
    aurvcssearch=".*-(cvs|svn|git|hg|bzr|darcs)$"
    mapfile -t vcspacks < <(awk -v "mask=$aurvcssearch" '$1 ~ mask {print $1}' <(aur repo --list))
    declare -a packstack
    aurcache='/pkg/aur/aurutils/sync'
    if [[ ${#vcspacks[@]} -eq 0 ]]; then
        printf "%s\n" "No vcs-packages to check, check your vcs-packages no?" && return 1
    else
        printf "%s\n" "Checking (${#vcspacks[@]}) vcs-packages for newer commits: ... "
    fi
    for pack in "${vcspacks[@]}"
    do
        if [[ -d $aurcache/$pack ]] && pacman -Q "$pack" > /dev/null 2>&1; then
            ftest=$( (cd $aurcache && aur srcver "$pack" 2>/dev/null) | awk '{print $2}')
            stest=$(pacman -Q "$pack" | awk '{print $2}')
            if [[ $(vercmp "$ftest" "$stest") -gt 0 ]]; then
                packstack+=( "${pack}" )
                printf "%s\n" "$pack has updates adding to stack ..."
            fi
        fi
    done
    if [[ ${#packstack[@]} -gt 0 ]]; then
        printf "%s\n" "Rebuilding (${#packstack[@]}) vcs-packages: ... "
        aur sync --rebuild "${packstack[@]}" && unset vcspacks && unset packstack
    else
        printf "%s\n" "No vcs-packages to update at this time." && unset vcspacks
    fi
}

Last edited by CarbonChauvinist (2021-02-05 02:09:24)


"the wind-blown way, wanna win? don't play"

Offline

#3509 2021-02-22 16:12:18

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,680
Website

Re: Post your handy self made command line utilities

Now that I have [gnome-unstable] and [testing] enabled i thought it would be a good idea to start taking daily btrfs snapshots, just in case...

/etc/systemd/system/snapshot.timer:

[Unit]
Description=Daily snapshot

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

/etc/systemd/system/snapshot.service:

[Unit]
Description=Daily snapshot

[Service]
Type=oneshot
ExecStart=/usr/local/bin/snapshot

/usr/local/bin/snapshot:

#!/bin/sh

time=$(date +'%Y-%m-%d@%T')
grub_dir=/boot/grub
config_file="$grub_dir"/arch-snapshots.cfg
snapshot_dir=/snapshots
subvol_dir=/snapshots/arch
uuid=$(findmnt -o uuid -n /)
parameters='rw quiet'

get_snap_info() {
   snap_list=$(for snap in "$snapshot_dir"/* ; do printf '%s ' "$(basename -- "$snap")" ; done)
   snap_number=$(printf '%s\n' "$snap_list" | awk '{print NF}')
   old_snap=$(printf '%s\n' "$snap_list" | awk '{print $1}')
}

if grep -q ' / .*snapshots.*' /proc/self/mounts ; then
   printf 'Booted into snapshot, no action taken.\n'
else
   printf 'Removing old configuration file...\n'
   if [ -e "$config_file" ] ; then
      rm "$config_file"
   else
      printf 'No configuration file found.\n'
   fi
   printf 'Creating new snapshot...\n'
   btrfs subvolume snapshot / "$snapshot_dir"/"$time"
   get_snap_info
   while [ "$snap_number" -gt 5 ] ; do
      printf 'Removing excess snapshot...\n'
      btrfs subvolume delete "$snapshot_dir"/"$old_snap"
      get_snap_info
   done
   printf 'Creating new configuration file...\n'
   printf '#\n' > "$config_file"
   for entry in "$snapshot_dir"/* ; do
      for kernel in "$entry"/boot/vmlinuz-* ; do
         image=/boot/"${kernel##*/}"
         initrd=/boot/initramfs-"${image#*-}".img
         set -- "$entry"/boot/*-ucode.img
         if [ -e "$1" ] ; then
            initrd_line=$(printf 'initrd %s/%s/boot/%s %s/%s%s' "$subvol_dir" "${entry##*/}" "${1##*/}" "$subvol_dir" "${entry##*/}" "$initrd")
         else
            initrd_line=$(printf 'initrd %s/%s%s' "$subvol_dir" "${entry##*/}" "$initrd")
         fi
         ed "$config_file" > /dev/null <<!
1i
menuentry '${entry##*/} (${image#*-})' {
   search --fs-uuid --set=root $uuid
   linux $subvol_dir/${entry##*/}$image root=UUID=$uuid rootflags=subvol=$subvol_dir/${entry##*/} $parameters
   $initrd_line
}
.
w
!
      done
   done
   printf 'All done!\n'
fi

$snapshot_dir is the path to the directory that holds the snapshots in the running Arch system and $subvol_dir is the path to the directory that holds the snapshots in the root of the btrfs filesystem; $parameters are the kernel parameters to be applied in the GRUB menu entries that are created for the snapshots. The script deletes any old snapshots once there are more than five, edit the while loop to change this.

Use this stanza in /boot/grub/grub.cfg to add the snapshots:

submenu 'Arch snapshots' {
   source $prefix/arch-snapshots.cfg
}

$prefix defaults to the directory containing the grub.cfg file.

I don't use grub-mkconfig so the grub-btrfs package is of no use to me.

EDIT: for the snapshots to be bootable there should be no root partition line in /etc/fstab (custom filesystem options can be applied from the bootloader). Alternatively add a line to modify /etc/fstab in the newly-created snapshot.

Last edited by Head_on_a_Stick (2021-02-22 16:55:20)

Offline

#3510 2021-02-22 17:19:02

Flemur
Member
Registered: 2012-05-24
Posts: 72

Re: Post your handy self made command line utilities

Here's one I use regularly, I call it W (from 'which'); it finds executables in your $PATH given one or two parts of the name.
I don't remember how it works...

#!/bin/bash
# Find files in $PATH matching *$1* [| grep -i $2]
#
if [ $# -lt 1 ]
then
  echo Usage: `basename $0` pattern  [ pattern2 ]
  exit 1
fi

if [ $# -eq 1 ]; then
  echo $PATH | sed 's/^/ls -A /' | sed 's/:/ |grep -i '$1'; ls -A /g' | sed 's/$/ |grep -i '$1'/' | bash | sort
  exit 0
fi

if [ $# -eq 2 ]; then
  echo $PATH | sed 's/^/ls -A /' | sed 's/:/ |grep -i '$1'; ls -A /g' | sed 's/$/ |grep -i '$1'/' | bash | sort  | grep -i $2
  exit 0
fi

Try

W user
W ^user
W user ad
W ad user

"If you do not change direction, you may end up where you are heading." -- L.T.

Offline

#3511 2021-02-22 21:45:47

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

Re: Post your handy self made command line utilities

Flemur wrote:

I don't remember how it works...

Poorly, very poorly.  That's a rather ridiculous pipeline of seds and greps and even a parsing of ls in there.  All that can be done with a single find command:

find $PATH -regex <whatever>

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

Offline

#3512 2021-02-22 22:11:18

seth
Member
Registered: 2012-09-03
Posts: 49,974

Re: Post your handy self made command line utilities

It does not works…

IFS=: dirs=($PATH)
find ${dirs[@]} -name "*$1*" | grep $2

(bash only, won't even work w/ zsh because of IFS handling)

Online

#3513 2021-02-22 22:18:30

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Post your handy self made command line utilities

IFS=: find $PATH -name "*${1}*" -name "*${2}*" -printf '%P\n'

Last edited by respiranto (2021-02-22 22:19:41)

Offline

#3514 2021-02-22 22:30:04

seth
Member
Registered: 2012-09-03
Posts: 49,974

Re: Post your handy self made command line utilities

Did you try that? In which shell?

Here's weird behavior (which eschwartz can perfectly reasonably explain ;-)

$ bash
$ IFS=: find $PATH -name "*add*" -name "*user*"
find: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl’: Datei oder Verzeichnis nicht gefunden
$ IFS=: find $PATH -name "*add*" -name "*user*"
find: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl’: Datei oder Verzeichnis nicht gefunden
$ IFS=: dirs=($PATH)
$ IFS=: find $PATH -name "*add*" -name "*user*"
/usr/bin/useradd

Also we probably need "-executable".

Online

#3515 2021-02-22 22:35:41

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Post your handy self made command line utilities

I thought I had it tested...

IFS=:; find $PATH -name "*${1}*" -name "*${2}*" -printf '%P\n'

On weird behaviour:
The line:

IFS=: dirs=($PATH)

sets two variables.

---

seth wrote:

Also we probably need "-executable".

find -P $PATH -mindepth 1 -maxdepth 1 -executable -xtype f -name "*${1}*" -name "*${2}*" -printf '%P\n' | sort -u

It would be nice to allow for regexes.  Unfortunately, `-(i)regex' matches the whole path and implicitly embeds the pattern in '^' and '$'.  I could not come up with something better than the following:

#!/usr/bin/env bash
typeset -a args=()

for p in "$@" 
do
  p=".*${p}.*"
  p="${p#.\*^}"
  p="${p%$.\*}"
  args+=(-iregex ".*/${p}")
done 
  
IFS=:
find -P $PATH -mindepth 1 -maxdepth 1 -executable -xtype f \
  -regextype posix-extended "${args[@]}" -printf '%P\n' \
  | sort -u

Alternatively, without explicit loop, unreadable, and still long:

#!/usr/bin/env bash
set -- "${@/#/.\*}"
set -- "${@#.\*^}"
set -- "${@/%/.\*}"
set -- "${@%\$.\*}"
set -- "${@@Q}"
eval "set -- ${@/#/-iregex .\\\*\/}"

IFS=:
find -P $PATH -mindepth 1 -maxdepth 1 -executable -xtype f \
  -regextype posix-extended "$@" -printf '%P\n' \
  | sort -u

Last edited by respiranto (2021-02-22 23:27:00)

Offline

#3516 2021-02-22 23:54:58

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

Re: Post your handy self made command line utilities

I'm pretty sure that used to work, but it works fine here just setting IFS - and there is definitely no need for a pipeline and certainly no need for a loop, if you want to use two regex's just use two regexs:

IFS=:; find $PATH -regex <pattern1> -regex <pattern2>

Last edited by Trilby (2021-02-22 23:56:24)


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

Offline

#3517 2021-02-23 13:02:35

seth
Member
Registered: 2012-09-03
Posts: 49,974

Re: Post your handy self made command line utilities

On weird behaviour:

With more blood and caffeine in my brains it's kinda obvious that IFS is relevant in the context of the shell, not the command.
So you somehow™ have to explicitly set it for that context (and use a subshell…)

Online

#3518 2021-02-23 18:49:10

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,794
Website

Re: Post your handy self made command line utilities

Dumping EC content. Output: https://i.imgur.com/aeJGJd6.png

// Dump laptop's EC content
// Might need modprobe ec_sys
package main

import (
	"fmt"
	"os"
)

const ec = "/sys/kernel/debug/ec/ec0/io"

const reset = "\033[0m"
const red = "\033[31m"
const green = "\033[32m"

func main() {
	fd, err := os.Open(ec)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}
	buf := make([]byte, 1)
	for i := 0; i < 16; i++ {
		fmt.Fprintf(os.Stdout, " %s%02X%s", green, i*16, reset)
		for j := 0; j < 16; j++ {
			fd.Read(buf)
			if int(buf[0]) == 0 {
				fmt.Print(" 00")
				continue
			}
			fmt.Fprintf(os.Stdout, " %s%02X%s", red, buf[0], reset)
		}
		fmt.Println()
	}
	fmt.Print("   ")
	for i := 0; i < 16; i++ {
		fmt.Fprintf(os.Stdout, " %s%02X%s", green, i, reset)
	}
	fmt.Println()
}

Consequent utility for writing to EC registers

// Write to EC register
// Might need 'modprobe ec_sys write_support=1'
// Values must be Hex
// Example: ecwrite e3 ff
package main

import (
	"fmt"
	"os"
)

const ec = "/sys/kernel/debug/ec/ec0/io"

func main() {

	register := os.Args[1]
	var r uint8
	if _, err := fmt.Sscanf(register, "%x", &r); err != nil {
		fmt.Fprintf(os.Stderr, "Invalid register %s\n", register)
		os.Exit(1)
	}
	value := os.Args[2]
	var v uint8
	if _, err := fmt.Sscanf(value, "%x", &v); err != nil {
		fmt.Fprintf(os.Stderr, "Invalid value %s\n", value)
		os.Exit(1)
	}
	fd, err := os.OpenFile(ec, os.O_RDWR, 0600)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	_, err = fd.WriteAt([]byte{byte(v)}, int64(r))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

Last edited by ugjka (2021-02-24 15:51:27)


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#3519 2021-03-01 22:44:19

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Post your handy self made command line utilities

seth wrote:

Did you try that? In which shell?

Here's weird behavior (which eschwartz can perfectly reasonably explain ;-)

$ bash
$ IFS=: find $PATH -name "*add*" -name "*user*"
find: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl’: Datei oder Verzeichnis nicht gefunden
$ IFS=: find $PATH -name "*add*" -name "*user*"
find: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl’: Datei oder Verzeichnis nicht gefunden
$ IFS=: dirs=($PATH)
$ IFS=: find $PATH -name "*add*" -name "*user*"
/usr/bin/useradd

Indeed, as others have noted -- the only time you ran the command line for find, with an IFS of ":" was the last time (because `IFS=: dirs=($PATH)` performed two assignments into the shell environment).

Using IFS for this is apparently not so great, since you likely want to save/restore it and you forgot to. tongue

Another alternative:

IFS=: read -a paths <<< "$PATH"
find "${paths[@]}" -name "*add*" -name "*user*"

<<< does utilize a temp file which is slightly wasteful. The read builtin performs splitting based on its own private copy of IFS.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3520 2021-03-10 10:07:40

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

Re: Post your handy self made command line utilities

I'm doing some fitness at home and since i strarted to suffer from pain to my elbows, i researched a bit and discovered the power of Isometric exercizes, where you have to hold a position for a given amount of time.
Quick script i plan to run on my phone via arch installed in a chroot, is in italian, but i think it is easilly understandable:

#!/bin/bash

if [ "$#" != 3 ]; then 
	echo Uso: "$(basename $0) tempo_esercizio tempo_pausa ripetizioni"
	exit 
fi

tempo_esercizio=$1
tempo_pausa=$2
ripetizioni=$3

bold="\e[1m"
rosso="\e[31m"
verde="\e[32m"
blu="\e[34m"
giallo="\e[93m"
reset="\e[0m"


countdown(){
	for i in $(seq $2 -1 1) ; do
		echo -ne "$bold\033[s \033[K \033[2B \033[100D$1:$verde Mancano $i secondi \033[u$reset"
		sleep 1
	done
	echo 
}
countdown "Preparati" 20
for i in $(seq 1 $ripetizioni) ; do
	countdown "Esercizio $i di $ripetizioni" $tempo_esercizio
	if ! [ $i = $ripetizioni ] ; then countdown "Pausa" $tempo_pausa ; fi
done

echo Finito.

Last edited by kokoko3k (2021-03-10 10:35:29)


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

Online

#3521 2021-03-10 11:13:50

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

Re: Post your handy self made command line utilities

Using shell scripts on Android is just nice. I use Termux instead of Arch, because it has interfaces for many Android functions that can easily be called from a script, like termux-sms-list, can speak via the TTS engine and even manipulate the wifi connection.

Offline

#3522 2021-03-10 11:42:55

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

Re: Post your handy self made command line utilities

Yeah, i've termux as well, but i made the chroot long time ago, when termux was not yet a thing.
Also, you can still script the escape from the chroot for a while and do neat things via adb.
...and doing pacman -Suy on an x86_64 phone is still nice smile (that reminds me that the kernel is too old and soon or later glibc will complain and i'll go 100% for termux as well)

Last edited by kokoko3k (2021-03-10 11:55:37)


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

Online

#3523 2021-03-10 12:54:26

seth
Member
Registered: 2012-09-03
Posts: 49,974

Re: Post your handy self made command line utilities

kokoko3k wrote:

I'm doing some fitness at home and since i strarted to suffer from pain to my elbows, i researched a bit and discovered the power of Isometric exercizes, where you have to hold a position for a given amount of time.

Stop that.
When you supinate the forearm (you can see your palm) and stretch your ringfinger (pull it away from the palm), does it hurt more and on the inside of your ellbow?

To stay somewhat on topic and get Trilby a cardiac arrest, here's my interval timer script (I'll post missing sources in subsequent posts)

#!/bin/bash

#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#                    Version 2, December 2004
#
# Copyright (C) 2016 Thomas Lübking, https://github.com/luebking/nodesk
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this script, and changing it is allowed as long
# as the name is changed.
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
#

OSD_BG='#272727'
OSD_FG='#fafafa'
OSD_HOT='#ff9100'
OSD_COLD='#00d1e1'

. $HOME/.config/nodesk.theme

# override
OSD_FONT="IBM 3270 Narrow-256"
OSD_FONT="Droid Sans Mono-256"

. $HOME/bin/.funcs/screengeo.sh

WIDTH=$((256*5 + 16)) # 256 px font width est.

ACTIONS="onstart=uncollapse,unhide"
ACTIONS="${ACTIONS};button1=exit:1"


beep() {
    for ((i=0;i<$1;++i)); do
        aplay -q ~/.local/share/sounds/beep_440.wav
        sleep $2
    done
}

beeeep() {
    for ((i=0;i<$1;++i)); do
        aplay -q ~/.local/share/sounds/beep_880.wav
        sleep $2
    done
}

get_primary_output_coords

dzen2 -u -e "$ACTIONS" -y $((SY + (SH - 512)/2)) -x $((SX + (SW - ${WIDTH})/2)) -sa c -l 0 -w $WIDTH -fn "$OSD_FONT" -bg "$OSD_BG" -fg "$OSD_FG" < \
<( #echo "$3" # Title

for ((i=5; i>0; --i)); do
    ((i==2)) && beep 3 0.8 &
    printf "^fg($OSD_COLD)%02d:%02d\n" 0 $i
    sleep 1
done

beeeep 1 0 &

SWITCH=0
if (($# > 3)); then
    CYCLES=$# # arbitrary chain
    TIMES=("$@")
elif (($# > 2)); then
    CYCLES=$((2*$3 - 1)) # hot - cold - reps
elif (($# > 1)); then
    CYCLES=19 # hot - cold - 19 times should trash you. Work harder!
else
    CYCLES=1 # degenerated countdown
fi
while ((++SWITCH <= $CYCLES)); do
    if ((SWITCH%2)); then
        COUNT=$1
        COLOR=$OSD_HOT
    else
        COUNT=$2
        COLOR=$OSD_COLD
    fi
    (($# > 3)) && COUNT=${TIMES[SWITCH-1]}
    for ((i=$COUNT; i>0; --i)); do
        if ((SWITCH%2)); then
            ((i == COUNT/2)) && beep 1 0 &
            ((i == COUNT/4 && i > 5)) && beep 2 0.1 &
            ((i == 1)) && beeeep 1 0 &
        else
            ((i == 2)) && beep 3 0.8 &
        fi
        printf "^fg($COLOR)%02d:%02d\n" $((i/60)) $((i%60))
        sleep 1
    done
done
)

Online

#3524 2021-03-10 14:51:58

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

Re: Post your handy self made command line utilities

seth wrote:
kokoko3k wrote:

I'm doing some fitness at home and since i strarted to suffer from pain to my elbows, i researched a bit and discovered the power of Isometric exercizes, where you have to hold a position for a given amount of time.

Stop that.
When you supinate the forearm (you can see your palm) and stretch your ringfinger (pull it away from the palm), does it hurt more and on the inside of your ellbow?

A bit, yes.
I think it is called epicondylitis in english, it hurts in the 'inside part' of the elbow when i do some movements, like using the smartphone and then put it down or after playing the guitar (damn!)
Maybe i did wrong exercises in the past and/or my new dog is too strong, but now, with isometric exercises like plank and variants (always with the folded arm and the elbow and forearm 'resting' still on the ground), i never use the hurting muscle and tendon.
Over a week i observed the pain slowly fade away.
Do you still think i need to stop plank and similar too?

Sorry guys for the OT

Last edited by kokoko3k (2021-03-10 15:15:11)


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

Online

#3525 2021-03-10 15:19:30

seth
Member
Registered: 2012-09-03
Posts: 49,974

Re: Post your handy self made command line utilities

I think it is called epicondylitis in english

Yes, is. If the ringfinger hurts most, it's https://en.wikipedia.org/wiki/Golfer%27s_elbow

"A plank is an isometric, but isometrics aren't planks." -- somebody

You're however this way working your core and do the important thing which is to leave the tendon alone (the ellbow is flexed, the forearm in a neutral position and resting - so the muscle on the tendon is absolutely not stretched)
Core (there's better stuff than planks unless you're an absolute beginner, but don't hook your feet under something and focus on the abs when raising your legs) and lower body workout (don't skip leg day!) is generally fine, but eg. an isometric hold on a pull-up bar isn't (it's putting a similar stress on the tendon)

The way you get this is from overusing the forearm, particularily on curls or chin-ups (and the reason for that is usually that you use too much weight and as a result a shit form)
Your dog pulling on the leash will aggrevate the irritation (any stretch on the forearm muslce that makes you flex your wrist will), but isn't the cause (unless you maybe walk your dog Trump-style, search it smile

Once the pain is gone and you waited 3-6 days (depending on how old you are ;-) you can
a) return to regular training, but if you want to train your biceps (the bro-chialis) make sure to train that, not your forearm
b) explicitly train the forearm muscles WITH FAR LESS WEIGHT - it's mostly wrist flexion and grip strength

Also probably reduce the frequency (ie. instead of working the bro-muscles every single day, don't skip leg day! smile



The function to get the primary screen geometry

get_primary_output_coords() {
    read SW SH SX SY < <(xrandr --current | sed '/ connected/!d; / primary/!d; s/.* \([0-9]*[^ ]*x[^ ]*+[^ ]*+[^ ]*\) .*/\1/; s%/[0-9]*%%g; s/[^0-9]/ /g')
    if ((SW < 1)); then
        read SW SH SX SY < <(xrandr --current | sed '/ connected/!d; s/.* \([0-9]*[^ ]*x[^ ]*+[^ ]*+[^ ]*\) .*/\1/; s%/[0-9]*%%g; s/[^0-9]/ /g')
    fi
}

Online

Board footer

Powered by FluxBB