home.social

#shellscripting — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #shellscripting, aggregated by home.social.

  1. Wrote a #shell function without using ls inside of $( ), so my inner @mirabilos won't harass me. XD

    #slightly easier wireguard command
    function wg {
        local dir file profile profiledir= parm=${1:-} statustext
        #Find profile dir
        for dir in {,/usr/local}/etc/wireguard; do
            if [[ -d $dir ]]; then
                profiledir=$dir
                break
            fi
        done
        #Find config file
        if [[ -n $profiledir ]]; then
            for file in $profiledir/*.conf; do
                if [[ -e $file ]]; then
                    profile=${file//*\/}
                    profile=${profile/.conf}
                    break
                fi
            done
        fi
        [[ -n $profile ]] || profile=proton
        statustext="wireguard profile $profile"
        case ${parm,,} in
            up|on)      doas wg-quick  up  $profile;;
            down|off)   doas wg-quick down $profile;;
            status)     echo -en "$statustext _______\r"
                        echo -en "$statustext "
                        ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;;
            *)          warn "wg usage: wg up|down|status";;
        esac
    }
    

    Hmm, seems ${foo,,} for lower case conversion is #bash-only. I wonder if I should use tr instead.

    #Unix #UnixShell #ShellScript #ShellScripting

  2. Recursion usually scares me a bit, but it worked out nicely here:

    #convert "cx"-style Esperanto notation to native accents (ĉ)
    function eaccent {
        if [[ ${1:-} ]]; then
            echo "$*" |eaccent
        else
            sed 's/cx/ĉ/g; s/gx/ĝ/g; s/hx/ĥ/g; s/jx/ĵ/g; s/sx/ŝ/g; s/ux/ŭ/g; s/C[xX]/Ĉ/g; s/G[xX]/Ĝ/g; s/H[xX]/Ĥ/g; s/J[xX]/Ĵ/g; s/S[xX]/Ŝ/g; s/U[xX]/Ŭ/g'
        fi
    }
    

    #bash #unix #shell #scripts #scripting #UnixShell #ShellScripting #Esperanto

  3. 🐢💤 Behold the revolutionary art of making Git diffs more complex than assembling IKEA furniture! All you need is #Delta, #fzf, a sprinkle of shell scripting, and the willingness to never see the sunlight again. Truly, the pinnacle of productivity hacks for those with too much time on their hands! 🙄🔧
    nickjanetakis.com/blog/awesome #GitDiffs #ProductivityHacks #ShellScripting #TechHumor #HackerNews #ngated

  4. TL;DW for the video:

    Lock Fix: Detects/removes stale db.lck.

    PGP Engine: Auto-fetches missing keys.

    Wiki Deep-link: [w] opens the specific Wiki page for the error.

    Smart Search: Finds package owners for missing binaries.

    Repo: github.com/Rakosn1cek/mend (2/2)

    #ShellScripting #ArchLinux #Dotfiles #DevLog

  5. Bash expansion explained for beginners. Learn brace, tilde, parameter, command, arithmetic, process, globbing, word splitting, and quote removal with practical examples.

    Full guide here: ostechnix.com/bash-expansion-b

    #BashExpansion #Bash #ShellScripting #Linux #Linuxhowto

  6. Here's a little puzzle for you. Can you figure out the purpose of this one-off shell script I just wrote?
    If you post an answer put it behind a CW so you don't spoil it for others!
    #programming #scripting #shellScript #shellScripting #Linux

  7. Am I the only one that never, ever uses getopt/getops in shell scripts?

    Just writing your own argument parser seems so much easier to do. :/

    #Unix #shell #bash #ShellScripts #ShellScripting

  8. Se vienen cositas próximamente en el blog y en el canal de YouTube 💪

    Intentando aclarar algunos conceptos fundamentales de SSH para poder utilizarlo como un pro y no morir en el intento 🚀

    ¿Todavía no nos siguen? 👇

    ▶️ youtube.com/juncotic?sub_confi

    📚 juncotic.com/blog

    🎓 juncotic.com/cursos

    ¡Los esperamos para seguir aprendiendo juntos!

    #gnu #linux #ssh #curso #firewall #iptables #nftables #wireshark #redes #tcpip #ciberseguridad #python #flask #shellscripting #juncotic

  9. Shell Scripting in 20 Minutes – Crash Course | In One Video for Beginners | MPrashant

    linux #mprashant #shellscripting #linuxtutorial Hello Dosto: In this video I have covered all the Shell Scripting Concept in just 1 ... source

    quadexcel.com/wp/shell-scripti

  10. Bash turns 38 today! Celebrate Bash's 38th birthday with 38 built-in features and essential tips. Learn keyboard shortcuts, parameter expansion, conditionals & more.

    Full guide here: ostechnix.com/38-bash-tips-she

    #Bash #Shell #Bash38 #Linux #Bashtips #Shelltips #Shellscripting #Linuxhowto #Linuxbasics #Linuxcommands

  11. #PSA regarding #GNU #coreutils #sort's unexpected or at least non-intuïtive behaviour of its --unique (-u) option together with --numeric (-n) or --human (-h).

    The output of piping something through

    sort -nu

    might not be equal to the output of piping the same thing through

    sort -n | uniq

    as it might miss some lines completely. 🤌

    And it's NOT documented in the man page, just in the info page.

    Related bug reports:

    debbugs.gnu.org/cgi/bugreport.
    bugs.debian.org/893524

    #WTF #CLI #Shellscripting

  12. 🧹 Tidying Up After Myself: Automatically Deleting Old GitHub Issues

    At some point, I had to admit it: I’ve turned GitHub Issues into a glorified chart gallery. Let me explain. Over on my amedee/ansible-servers repository, I have a workflow called workflow-metrics.yml, which runs after every pipeline. It uses yykamei/github-workflows-metrics to generate beautiful charts that show how long my CI pipeline takes to run. Those charts are then posted into a GitHub Issue—one per run. It’s neat. It's visual. It's entirely unnecessary to keep them […]

    amedee.be/%f0%9f%a7%b9-tidying

  13. Building off of what we learned at #Macstock2025 from @TheMikeBurke, I automated building new project folders using shell scripting and Keyboard Maestro. I had more fun doing that than starting my ScreenCastsONLINE project. Don't tell @leegarrett

    podfeet.com/blog/2025/08/autom

    #Automation #ShellScripting #KeyboardMaestro

  14. Shell two-liner to watch your phone battery via KDE Connect while charging (or discharging):

    alias kcbatt='qdbus6 org.kde.kdeconnect /modules/kdeconnect/devices/$(grep -Em1 "^\[[0-9a-f_]+\]" ~/.config/kdeconnect/trusted_devices |tr -dc 0-9a-f_)/battery org.kde.kdeconnect.device.battery.charge'
    
    ob=0; while b=$(kcbatt); do if ((ob!=b)); then date "+%H:%M $b%%"; ob="$b"; fi; sleep 5; done
    

    #KDE #KDEConnect #ShellScripting #OneLiner #Useful

  15. Shell two-liner to watch your phone battery via KDE Connect while charging (or discharging):

    alias kcbatt='qdbus6 org.kde.kdeconnect /modules/kdeconnect/devices/$(grep -Em1 "^\[[0-9a-f_]+\]" ~/.config/kdeconnect/trusted_devices |tr -dc 0-9a-f_)/battery org.kde.kdeconnect.device.battery.charge'
    
    ob=0; while b=$(kcbatt); do if ((ob!=b)); then date "+%H:%M $b%%"; ob="$b"; fi; sleep 5; done
    

    #KDE #KDEConnect #ShellScripting #OneLiner #Useful

  16. Shell two-liner to watch your phone battery via KDE Connect while charging (or discharging):

    alias kcbatt='qdbus6 org.kde.kdeconnect /modules/kdeconnect/devices/$(grep -Em1 "^\[[0-9a-f_]+\]" ~/.config/kdeconnect/trusted_devices |tr -dc 0-9a-f_)/battery org.kde.kdeconnect.device.battery.charge'
    
    ob=0; while b=$(kcbatt); do if ((ob!=b)); then date "+%H:%M $b%%"; ob="$b"; fi; sleep 5; done
    

    #KDE #KDEConnect #ShellScripting #OneLiner #Useful

  17. In the helpful shell functions department:

    (Requires bc to be installed)

    load() {
        local load=$(uptime |sed -E "s/^.*load averages?: //; s/,.*$//")
        local uname="$(uname)"
        local cpus
        if [[ $1 == -q ]]; then
            echo "$load"
        elif [[ $1 == -i ]]; then
            echo "$load + 0.5" |bc -l |cut -f1 -d.
        else
            case "$uname" in
                Linux)  cpus=$(grep -c ^processor /proc/cpuinfo);;
                *BSD)   cpus=$(sysctl hw.ncpu |tr -dc "0-9\n");;
                *)      warn "load(): assuming 1 cpu, don't know how to get the number in \"$uname\""
                        cpus=1;;
            esac
            local loadPerCPU=$(echo "scale=3; $load / $cpus" |bc -l |sed 's/^\./0./')
            echo "$load ($loadPerCPU per processor ($cpus))"
        fi
    }
    

    #ShellScripting #UnixShell #ShellScripts #bash #ksh #sh

  18. #Poll: Curious about people's attitudes towards shell scripting.

    Two part question:

    1. Are you a DEVeloper (or working in a development-heavy role), OTHER-IT worker (such as a sysadmin, architect, anything in a non-development-heavy role), or NON-IT (accountant, doctor, whatever)
    2. Do you HATE shell scripting, are you INDIFferent towards (or ignorant of) shell scripting, or do you LOVE it?

    #Unix #UnixShell #ShellScript #ShellScripting #POSIX #PosixShell #sh #bash #zsh #csh #tcsh #ksh #pdksh #oksh #mksh

  19. I'm exploring ways to improve audio preprocessing for speech recognition for my [midi2hamlib](github.com/DO9RE/midi2hamlib) project. Do any of my followers have expertise with **SoX** or **speech recognition**? Specifically, I’m seeking advice on: 1️⃣ Best practices for audio preparation for speech recognition. 2️⃣ SoX command-line parameters that can optimize audio during recording or playback.
    github.com/DO9RE/midi2hamlib/b #SoX #SpeechRecognition #OpenSource #AudioProcessing #ShellScripting #Sphinx #PocketSphinx #Audio Retoot appreciated.

  20. Gotta say, I wish #bash had local / lexically-scoped functions, rather than having to rely on hacks like:

    function widget {
        function ___widget_parse {
            ...
        }
        ...
        unset ___widget_parse
    }
    

    Something like this (which does not currently work) would be lovely:

    function widget {
        local function parse {
            ...
        }
    }
    

    #ShellScript #ShellScripts #ShellScripting

  21. If you're a #Linux person and using the command "ps" with options like "aux" instead of e.g. "-e" (i.e. options without leading "-"), you likely learned the #Unix #commandline on #BSD or maybe SunOS 🧔. (Or by someone who grew up with them. 🙂)

    In other news: #TIL that (in either variant) the option "j" (e.g. as "ps ajx" or "ps -ej") also shows the PPID (parent PID, only with BSD style options), PGID (process group ID) und SID (session ID).

    #cli #commandlinemagic #ps #shellscripting

  22. Pnut: A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell - Shell scripting is one of those skills that are absolutely invaluable on especiall... - hackaday.com/2024/07/25/pnut-a #softwaredevelopment #shellscripting #transpiler

  23. Hey ( / / users in particular),

    Does anyone have a preferred front-end to keepassxc-cli? I know there's a rofi interface shell script, but I honestly found it kind of clunky.

    This is something that could be very easily and nicely shell scripted, and I wanted to ask if anyone knows of one out there already before I re-invented the wheel.

  24. I've recorded a screencast for my old bash script alltests — test runner for competitive programming. It runs an executable against set of static tests (sample inputs and outputs).

    #asciinema #competitiveProgramming #bash #ShellScripting #utility #testing

  25. While I've been waiting on packages to compile for ELFS I've been playing with xonsh in between builds.

    Xonsh is a python-powered shell. I don't often use python, but have started growing a liking to it with xonsh.

    It's got some pretty neat features and expands the capabilities of a traditional shell greatly.

    What stood out to me the most is the fact that the PATH environment variable is an array and not a string. This is a quirk I've only ever seen in the rc shell from Plan 9. It's actually a really good quirk too! This feature actually makes it easier to script and manipulate the PATH variable in many ways.

    While my demonstration is not particularly impressive I think it's kinda neat how python and shell are intertwined in such a nice way.

    #python #shellscripting #shell #elfs #xonsh #linux #linuxengineer

  26. Searching for "New York" followed by one or more capitalised words ... and massaging the resulting data a bit, results in the following list of New York institutions and/or aspects which receive mention at HN:

      96  New York Times
    51 New York City
    25 New York
    5 New York State
    4 New York Public Library
    3 New York City Subway
    2 New York Harbor
    2 New York Subway
    2 New York Times Magazine
    1 New York Attorney General
    1 New York Charity
    1 New York City Campus
    1 New York Fed
    1 New York Libraries
    1 New York Magazine
    1 New York Police
    1 New York Post
    1 New York Region
    1 New York Senate

    Note that the 3rd entry, "New York" is itself ambiguous, and can refer to the city, state, or metro region, amongst others.

    A handy reminder that language is itself ambiguous and provides a useful but not precise mechanism for transferring meaning or understanding (or sometimes ambiguity and confusion) between entities.

    #HN #HackerNews #DataAnalysis #ShellScripting #GlobalCities #MediaAnalysis

  27. HN Front Page / Global Cities Mentions

    One question I've had about HN is how well or poorly it represents non-US (or even non-Silicon Valley) viewpoints and issues.

    Pulling from the Globalization and World Cities Research Network list, the top 50 global cities names appearing in HN front-page titles:

      1   191  San Francisco
    2 164 London
    3 117 Boston
    4 86 Seattle
    5 60 Tokyo
    6 58 Paris
    7 56 Chicago
    8 56 Hong Kong
    9 55 New York City
    10 50 Berlin
    11 50 Phoenix
    12 45 Rome
    13 40 Detroit
    14 36 Singapore
    15 31 Vancouver
    16 30 Los Angeles
    17 27 Austin
    18 23 Beijing
    19 20 Dubai
    20 19 Shenzhen
    21 19 Toronto
    22 17 Amsterdam
    23 16 Copenhagen
    24 16 Houston
    25 16 Moscow
    26 15 Atlanta
    27 14 Barcelona
    28 14 Denver
    29 13 Baltimore
    30 13 San Jose
    31 13 Stockholm
    32 12 San Diego
    33 12 Sydney
    34 11 Cairo
    35 10 Munich
    36 10 Wuhan
    37 9 Helsinki
    38 9 Miami
    39 9 Mumbai
    40 9 Philadelphia
    41 9 Shanghai
    42 9 Vienna
    43 8 Montreal
    44 7 Beirut
    45 7 Dublin
    46 7 Istanbul
    47 6 Bangalore
    48 6 Dallas
    49 6 Kansas City
    50 6 Minneapolis

    (Best viewed in original on toot.cat.)

    Note that some idiosyncrasies affect this, e.g., "New York City" appears rarely, whilst "New York" may refer to the city, state, any of several newspapers, universities, etc. "New York" appears 315 times in titles (mostly as "New York Times").

    I've independently verified that, for example, "Ho Chi Minh City" doesn't appear, though "Ho Chi Minh" alone does:

    news.ycombinator.com/item?id=1, on the 2017-9-30 front page: news.ycombinator.com/front?day

    So apply salt liberally.

    Edits: tyops & speling.

    #HN #HackerNews #DataAnalysis #ShellScripting #GlobalCities #MediaAnalysis

  28. Linux Fu: Leaning Down with exec - Shell scripting is handy and with a shell like bash it is very capable, too. However, shell scriptin... more: hackaday.com/2019/12/30/linux- #hackadaycolumns #shellscripting #linuxhacks #linuxfu #skills #linux #bash #exec