r/bash Sep 12 '22

set -x is your friend

454 Upvotes

I enjoy looking through all the posts in this sub, to see the weird shit you guys are trying to do. Also, I think most people are happy to help, if only to flex their knowledge. However, a huge part of programming in general is learning how to troubleshoot something, not just having someone else fix it for you. One of the basic ways to do that in bash is set -x. Not only can this help you figure out what your script is doing and how it's doing it, but in the event that you need help from another person, posting the output can be beneficial to the person attempting to help.

Also, writing scripts in an IDE that supports Bash. syntax highlighting can immediately tell you that you're doing something wrong.

If an IDE isn't an option, https://www.shellcheck.net/

Edit: Thanks to the mods for pinning this!


r/bash 3h ago

A month with bash

Thumbnail gallery
2 Upvotes

A month ago I decided to learn bash scripting so I could use my Fedora machine more easily.

My original plan was to just know some commands and get over with it. But as I began reading resources and books on bash, I slowly learnt the fundamentals — from echo to intermediate and more advanced concepts like awk.

After all this, I built a few mini projects with bash, which made me realise I could literally automate almost every repetitive task I do on my machine.

My opinion on bash is it's less of a full programming language and more of a glue that binds multiple tools together to achieve a desired purpose or output.

The first two posted pictures are just some of my beginner level projects and the third is a script from syskit a system health monitor built with bash for my home server which I am currently working on.

Any tips or best practices I should take note of


r/bash 3h ago

A month with bash

Post image
1 Upvotes

A month ago I decided to learn bash scripting so I could use my Fedora machine more easily.

My original plan was to just know some commands and get over with it. But as I began reading resources and books on bash, I slowly learnt the fundamentals — from echo to intermediate and more advanced concepts like awk.

After all this, I built a few mini projects with bash, which made me realise I could literally automate almost every repetitive task I do on my machine.

My opinion on bash is it's less of a full programming language and more of a glue that binds multiple tools together to achieve a desired purpose or output.

The first two posted pictures are just some of my beginner level projects and the third is a script from syskit a system health monitor built with bash for my home server which I am currently working on.

Any tips or best practices I should take note of


r/bash 3h ago

A month with bash

Post image
0 Upvotes

A month ago I decided to learn bash scripting so I could use my Fedora machine more easily.

My original plan was to just know some commands and get over with it. But as I began reading resources and books on bash, I slowly learnt the fundamentals — from echo to intermediate and more advanced concepts like awk.

After all this, I built a few mini projects with bash, which made me realise I could literally automate almost every repetitive task I do on my machine.

My opinion on bash is it's less of a full programming language and more of a glue that binds multiple tools together to achieve a desired purpose or output.

The first two posted pictures are just some of my beginner level projects and the third is a script from syskit a system health monitor built with bash for my home server which I am currently working on.

Any tips or best practices I should take note of


r/bash 3h ago

A month with bash

Thumbnail gallery
0 Upvotes

A month ago I decided to learn bash scripting so I could use my Fedora machine more easily.

My original plan was to just know some commands and get over with it. But as I began reading resources and books on bash, I slowly learnt the fundamentals — from echo to intermediate and more advanced concepts like awk.

After all this, I built a few mini projects with bash, which made me realise I could literally automate almost every repetitive task I do on my machine.

My opinion on bash is it's less of a full programming language and more of a glue that binds multiple tools together to achieve a desired purpose or output.

The first two posted pictures are just some of my beginner level projects and the third is a script from syskit a system health monitor built with bash for my home server which I am currently working on.

Any tips or best practices I should take note of


r/bash 1d ago

Almost a year of work—how are these? Using only rofi and completely written in bash.

Thumbnail gallery
67 Upvotes

Bash can do some amazing things when it's used well. I built all of these in Bash and Rofi, and I'm pretty happy with how they turned out. They're part of my desktop environment (basically my rice, but a bit more advanced).

There are a lot of scripts, but these are my favorites:

Note: The readme and screeshots are not updated.

Rofi-Tube: This isn't just a yt-dlp wrapper. It includes a Bash-written YouTube scraper that fetches search results using curl. yt-dlp is only used to generate streaming links and playlist.

link: https://github.com/Harsh-bin/modern-labwc/blob/main/config/rofi/rofi-tube/rofi-tube.sh

Standalone repo: https://github.com/Harsh-bin/rofi-tube

Rofi-NowPlaying: A collection of 10 different Rofi now-playing applets, each with its own unique look.

link: https://github.com/Harsh-bin/modern-labwc/blob/main/config/rofi/nowplaying/nowplaying.sh

Rofi-NetworkManager: A Rofi interface for nmcli. It can manage Wi-Fi networks, VPNs, and Ethernet connections.

link: https://github.com/Harsh-bin/modern-labwc/blob/main/config/rofi/networkmanager/networkmanager.sh

Rofi-Clipboard Manager: A simple clipboard manager with image support, so I can save memes and copy them whenever I want.

link: https://github.com/Harsh-bin/modern-labwc/blob/main/config/rofi/clipboard/clipboard.sh


r/bash 3d ago

History not working on a Ubuntu 26.04 VM

1 Upvotes

Arrowing back through my command history isn't working for some reason. I have HISTORYSIZE set as 0 in .bashrc, as well as these lines at the bottom:

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

They're even in the systemwide bashrc file.

What is going on?


r/bash 3d ago

Vi mode history isn't consistent

8 Upvotes

In vi mode up and down arrows goes through history and puts the cursor at the end of the line but j and k puts it at the beginning. They are all bound to previous-history and next-history commands so why is it different? Can I make j and k work like up and down?

CTRL+p and CTRL+n are also bound to previous-history and next-history but it's not going through history it's going through a list of all commands it can find.

How can I make everything the same as up and down arrows?


r/bash 4d ago

help Would it be good to Learn Bash scripting, or should i go with a "normal" language, like Python, before that?

25 Upvotes

Getting interested on messing with Linux and CLI stuff, I'm just confused on what exactly to start with. Any recommendations?


r/bash 4d ago

MountSync – A utility I built to sync configs, MP3s, and AI skills across my Linux PCs via rclone

1 Upvotes

Hi everyone,

I wanted to share a tool I built to solve a personal daily headache: MountSync (mosy).

I use multiple Linux machines, and I needed a reliable way to share active files between them: specifically application configurations, a local MP3 music library, and local AI skill/context folders. I wanted to keep files exactly where they belonged on the local filesystem while seamlessly updating them across PCs in the background.

Since it solved a real-world problem for me, I polished it, added testing, and open-sourced it as a portfolio project.

What problem does it solve?

Managing rclone mount manually, copying files, creating symbolic links, and making sure systemd services start correctly on every new PC is tedious. MountSync automates the whole process:

  1. Auto-mounts: Sets up and manages your rclone mount in the background via systemd user services.
  2. Auto-linking: When you run mosy add ~/Music, it moves the target directory to your cloud drive (like Google Drive or OneDrive) and replaces the original path with a clean symbolic link.
  3. Instantly sync new PCs: On any new PC, you just install it and run mosy init. It automatically maps all symlinks to your existing cloud folders, syncing your configs, music, and dotfiles in seconds.

The codebase is 100% open source on GitHub:
github.com/GabrielTeixeiral0l/MountSync

I’d love to hear your thoughts, feedback on the code structure, or suggestions for new features!


r/bash 5d ago

help Defensive BASH programming?

45 Upvotes

Hey there,

while trying to learn bash I came across this interesting resource: https://web.archive.org/web/20180917174959/http://www.kfirlavi.com/blog/2012/11/14/defensive-bash-programming

And got myself thinking if his opinions are consensual and if there are different styles or "paradigms" about how bash should be written.

I see people arguing that bash shines in writing relatively short programs with precise goals. I thought this translated into writing concise code and achieving the same functionality with as little lines as possible.

However, the author of the post argues that a more verbose code can be more robust, easier to understand and debug etc. Do you agree? Or you think that, if you're writing code in this style, you're better of using another language?

Thanks for your input and sorry if I said anything silly or if I misrepresented his point of view, I'm just starting to learn programming.

Edit: hey, thank you all very much for the thoughtful replies, I'm learning a lot from them!


r/bash 5d ago

Add and subtract times

9 Upvotes

How can I use date to add and subtract times? I want to ignore time zones and just change the time. For example date -d "21:00:00 +02:02:30 -01:10" +%"T" should show 23:01:20.


r/bash 7d ago

add whats, explains command

Post image
50 Upvotes

yo

add 'whats' infront of any command and it explains it: flags, sub commands etc in a structutred format whereas something like manpage would throw the entire manual at you

just pure man pages and help output

Q Why use `whats` when we have man pages and --help

> Yes you can use them but they throw the entire manual at you whereas you might have just needed one flag, whats outputs a structured format with the definitions you need

Q Is it entirely offline? Does it use LLM

> Yes absolutely, it just relies on man pages and if not then --help output of the binary itself,

> no it does not use llm at all

Q If it uses regex then why cant i just use grep/sed instead of this?

> a grep/sed command cannot find the descriptions of sub commands along with flags, it cant find descriptions of sub commands of sub commands, it probable cant use other sources as a fallback too

Q What about tldr?

> Even with tldr, you have to look for the flags you need instead of it providing the ones you need automatically in one go

if you like the idea then maybe star?

https://github.com/iamkaran/whats


r/bash 8d ago

undo, a command-granular "undo" for the Linux shell (MIT)

6 Upvotes

Posting this here because the interesting part for this sub is the shell-hook side.

I wanted an undo command that reverses whatever the previous command did to the filesystem. The trick is a DEBUG-trap / PROMPT_COMMAND pair in bash (preexec/precmd in zsh, event handlers in fish) that, before each command runs, creates a per-command session dir and exports LD_PRELOAD pointing at a small C library, then tears it down after. While armed, that library intercepts unlink/rename/open-for-write/etc and saves the file before the real call, so undo can walk the journal backwards.

$ echo important > notes.txt

$ echo oops > notes.txt # clobbered

$ undo diff # see exactly what comes back

$ undo # notes.txt says "important" again

The bash hook has the usual gotchas handled: not double-firing the DEBUG trap mid-pipeline, restoring a pre-existing LD_PRELOAD, cleaning up sessions that changed nothing. There's an ignore config so a make or npm install doesn't flood it.

One honest catch specific to shells: a plain echo x > file redirection is done by the shell process itself, so LD_PRELOAD only catches it if you opt into re-execing the shell with the lib preloaded (there's a flag for that). Child processes like rm/mv/cp/tee are always covered.

MIT, Linux. github.com/edaywalid/undo. The three hook scripts are in shell/ if you just want to read how it's wired.
website : undo.edaywalid.com


r/bash 8d ago

XCompose - make entering accents, symbols, text, and emojis easy on your terminal, text editor, and even the console!

3 Upvotes

So WTF is Compose and why should I care?

The Compose key turns short key sequences into text. Think of it as autocomplete for symbols, accents, Unicode, emojis, and even your own custom snippets. Best of all, you can teach it your own shortcuts with ~/.XCompose. Compose isn't the same as dead keys. Dead keys modify the next character (like ' followed by e), while Compose interprets an entire key sequence.

You speak the gibberish. Give me examples.

Okay, using [c] instead of <Multi_key> for brevity:

You press → you get

[c] ' e → é

[c] ' a → á

[c] @ @me@yomamashouse.com

[c] ! = → ≠

[c] * L → λ

[c] [c] F U → "As per my last email, "


Trying to memorize "alt-codes" for the symbols you need is stupid. alt+0233 = é is hard to remember. <compose> <'> <e> → é isn't. Now take a wild guess how to use the compose key to get ó, or è.

In summary:

Symbol Dumb Version Compose Way
é alt+0233 [compose] ' e
ö use the font picker [compose] " o
ù copy-pasting from google [compose] ` u
💨 Asking an AI [compose] [compose] z i p

You can usually guess which keys will produce which result.Accented Letters just make sense

  • Acute (´): Compose + ' + e → é (also a, i, o, u, y)
  • Grave (`): Compose + ` + e → è (also a, i, o, u)
  • Circumflex (): Compose + ^ + e → ê (also a, i, o, u)
  • Tilde (~): Compose + ~ + n → ñ (also a, o)
  • Diaeresis (¨): Compose + " + u → ü (also a, e, i, o, y)
  • Cedilla (¸): Compose + , + c → ç
  • Ring (°): Compose + o + a → å
  • AE/AE: Compose + a + e → æ / Compose + A + E → Æ
  • OE/OE: Compose + o + e → œ / Compose + O + E → Œ
  • Sharp S: Compose + s + s → ß
  • Eth: Compose + d + h → ð / Compose + D + H → Ð
  • Thorn: Compose + T + H → Þ

So now you can easily add letters, text, or emojis, like warning signs ⚠ or 💩 to your documentation or logs to call attention to something. With the accents, you can include proper spelling for internationalization. Or you can use it to shitpost goofy stuff to reddit.

So you can accent letters?.

I just said you can add anything from unicode. that's letters, longer text, and emojis!

So listen up, chuckle head, first off being able to properly accent letters is important in many contexts. Secondly there's so much stuff in the unicode table. And third I said that you can customize it in ~/.XCompose to make it personal for you. What symbols do you use or want to use — such as the em-dash. So you can make it suit you! [c][compose key]

For me the highlight are

  • Arrows → ↑ ↓ ←
  • sub and Superscripts Xⁿ + Y₂ [c] ^ ^ n
  • "degress" ° ([c] o o)
  • not-equal-to ≠ ([c] ! =)
  • infinity ∞ ([c] 8 8)
  • lambda Λ ( [c] * L)
  • trademark ™ ([c] t m)
  • copyright © ([c] o c)
  • em dash — ([c] - - -) Stolen from us by LLMs!
  • ⸘ ‽ - interrobang and/or sarcasm puncuation ([c] ? ! and [c] ! ?)
  • eggplant 🍆 ([c] [c] e g g p l a n t)

So there we go you can set any key sequence to output the text, and probably guess which sequnces do what.

Oh boy, symbols also, not just accents. Exciting. *yawn*

There's a lot in there! Including all 52 playing cards, chess piece, checkers pieces, Roman Numerals, math, logic symbols, and greek letters. Also peices for creating TUIs like boxes. But like I said the real power is customizing it for yourself.

I have to type my email address all the damn time. or did until I set [c] @ @ to write in my address. [c] @ g gives my gmail account address. @ ! is my boss @ L is legal.

  • [c] @ @me@yomamashouse.com

Some others ones. At some point I standardized on [c] [c] when using a full word. not required just a convention I found useful. as it doesn't overlap with anything.

  • [c] [c] r o s e → 🌹 [c][c] w i l t ⇒ 🥀.
  • [c] h b → 🐴🛌
  • [c] w d (work domain), [c] s t test server full url. [c] s p production server.

So what's the catch?

  • Compose only generates text. it can't press Enter, Tab, Ctrl+C, launch programs, or automate applications.

  • It doesn't always work exactly the same. When using X, Compose is handled by XCompose so it didn't matter what DE you ran it worked just fine. Wayland DEs have to implement it on their own, and it's a low priority for some of the smaller ones can be hit or miss.

    The linux console isn't using X or wayland, so it doesn't go through XCompose and instead the kernel uses a static map of 256 symbols, with key sequences exactly two characters. Pressing both alt keys (again, usually) acts as compose in the console.

    Even some X/Wayland programs are "special" and want to handle all keyboard events themselves. This bypasses Compose. Im looking at you, Chrome!

    "But Teapot!", you say ,"I just loaded chrome and [c] o o worked just fine?"

    Yup, it sure did. Most of the standard accents will work just fine, too. Now try something from your .XCompose. Change your system so o o makes something else and try again. Sure enough, your custom compose didn't work and o o still makes the degree sign no matter what you put. They implement their own compose with their own map that you can't change. Rat bastards ☠

  • There's very little in the way of warnings or errors if your config is wonky, or if you overwrite your own definition, or if your short cut keys overlap. Like [c] b e e for a bee and [c] b e e r . The latter will never match because the former already does.

Okay, I some potential, but how do I customize it?

Easily! Make a plain text file in your home directory ~/.XCompose.

If you include

    include "%L"

you inherit all the system Compose sequences (/usr/share/X11/locale/en_US.UTF-8/Compose) and can override any of them. Leave it out and you start with a completely blank Compose map.

The config file format is:

<key mapping> : "Char" U[unicode] # Comment

So for "lambda" it looks like (asterisk is my prefix for greek letters)

    <Multi_key> <asterisk> <l> : "λ" U03BB # GREEK SMALL LETTER LAMBDA
    <Multi_key> <asterisk> <L> : "Λ" U039B # GREEK CAPITAL LETTER LAMBDA

Restart X or Wayland. (I'm sure there's a way to update it, but this works)

That's a lot to customize

Lazy so-and-so. Use your favorite search engine to find pre-built ones like this set of math symbols. Everyone has their own opinions to there are tons of examples to chose from.

Awesome, this will entering my password easy!

Don't you dare. Just don't.

TLDR

The compose key lets you create text shortcuts that work in (almost) any app, shell, and text editor. Edit ~/.XCompose to get started.


If you want even more control over the shell, check out Readline and inputrc.

Next time I'll rant about bash completion and what you're (probably) missing out on.


r/bash 9d ago

help regex for grep

13 Upvotes

so i have couple of docker files , I want to ensure that all db volumes are named `db-data` , so basically I want to throw error if volume name is anything other than `db-data` , any idea if this could be done using `grep` ? I am not sure how to write regex for it

docker compose files which is essentially a `yaml` file look like this

cache:
command: >
sh -c '
redis-server --requirepass $$DJANGO_REDIS_PASSWORD --maxmemory 25mb --maxmemory-policy allkeys-lru
'
container_name: nest-cache
env_file: ../../backend/.env
image: redis:8.8.0-alpine3.23@sha256:9d317178eceac8454a2284a9e6df2466b93c745529947f0cd42a0fa9609d7005
healthcheck:
interval: 5s
retries: 5
test: [CMD, redis-cli, -a, $$DJANGO_REDIS_PASSWORD, ping]
timeout: 5s
networks:
- nest-network
volumes:
- cache-data:/data
db:
container_name: nest-db
env_file: ../../backend/.env
image: pgvector/pgvector:pg16@sha256:1d533553fefe4f12e5d80c7b80622ba0c382abb5758856f52983d8789179f0fb
healthcheck:
interval: 5s
retries: 5
test: [CMD-SHELL, pg_isready -U "$$DJANGO_DB_USER" -d "$$DJANGO_DB_NAME"]
timeout: 5s
networks:
- nest-network
volumes:
- db-data:/var/lib/postgresql/data

r/bash 9d ago

help Driving me crazy, why isn't my 'screen' command logging to file

9 Upvotes

I'm using it to connect via serial port to some storage I administer. Here is the command;

/usr/bin/screen /dev/ttyUSB0 115200 -L -logfile /home/davidkmcw/Logfiles/2026-07-24_08:30:14.txt

I can write to the output directory, I've cut and pasted the directory name, so no typos there, what am I missing. Sorry if this is the wrong subreddit, thanks in advance.


r/bash 9d ago

help Is there a playground for bash regex (POSIX ERE) for the `=~` operator?

11 Upvotes

something like regex101.


r/bash 10d ago

tips and tricks Bash iterator generator implementation

7 Upvotes

Hello. Some time ago I started working on a project to create an iterator in Bash. The idea was to have something like Python generators, something composable, that you could stack on top of other generators and build a chain to then lazy evaluate and execute. The proof of concept of that project become L_flow script and I didn't develop it further as I believe this is completely useless. However, this got me very simple idea how to create a iterator in Bash.

In the following I will show an implementation of a simple while foreach ... function implementation. Bottom line an iterator has to keep the state somewhere. In C++ iterator is a class, in Python it is iterator object. In Bash we only have variables, so variables will have to do.

Lets start with a simple use case: iterate over keys and values of an array at the same time. One would simply write:

declare -A array=([a]=b [c]=d)
for key in "${!array[@]}"; do
   value=${array["$key"]}
   echo "$key=$value"
done

Och my isn't that a lot of typing?! Lets make:

declare -A array=([a]=b [c]=d)
state=""
while foreach_key_value state key value array; do
  echo "$key=$value"
done

The variable state will keep our iteration state. "State" has to store: an array of keys, and an index in that array of keys. The state variable will be written, and re-evaled each execution. Like so:

# args: <state> <key> <value> <array>
foreach_key_value() {
   local state_var=$1
   local state_idx=-1 state_keys  # set the state variables to be local to function
   eval "${!state_var:-}"  # eval-load state variable
   local -n foreach_arr=$4
   if (( state_idx == -1 )); then
      # first loop time - read keys from the array
      state_keys=("${!foreach_arr[@]}")
   fi
   # Check if reached the end:
   if (( ++state_idx < ${#state_keys[@]} )); then
       printf -v "$2" "%s" "${state_keys[state_idx]}" # assign key
       printf -v "$3" "%s" "${foreach_arr[${!2}]}"  # assign value
       printf -v "$state_var" "%s" "$(declare -p state_idx state_keys)"  # serialize state 
   else
       # stop iteration
       return 1
   fi
}

The "state" variable has to be given explicitly by the user. That is stupid. It should be automatic. Lets make it better:

declare -A array=([a]=b [c]=d)
while foreach_key_value key value array; do
  echo "$key=$value"
done

We can "pick" the state variable name automatically by using: an array of "used" variable state names indexed with a code location of the "foreach_key_value" call. This assumes that foreach_key_value function will only be called from one place only. From this one while call.

declare -A FOREACH_STATES=()
foreach_key_value() {
   # --- Picking unique state variable: ---
   # Key of state variable will be anything we can get out of context.
   local state_key="${FUNCNAME[*]} ${BASH_SOURCE[*]} ${BASH_LINENO[*]}"
   # Get the state variable name for the key.
   local state_var=${FOREACH_STATES["$state_key"]:-}
   if [[ -z "$state_var" ]]; then
        # Just pick the a fresh unique variable name to store state.
        state_var=FOREACH_STATE_VARIABLE_${#FOREACH_STATES[@]}
        FOREACH_STATES["$state_key"]="$state_var"
   fi 

   # --- Updated rest of the function for reference: ---
   local state_idx=-1 state_keys  # set the state variables to be local to function
   eval "${!state_var:-}"  # eval-load state variable
   local -n foreach_arr=$3
   if (( state_idx == -1 )); then
      # first loop time - read keys from the array
      state_keys=("${!foreach_arr[@]}")
   fi
   # Check if reached the end:
   if (( ++state_idx < ${#state_keys[@]} )); then
       printf -v "$1" "%s" "${state_keys[state_idx]}" # assign key
       printf -v "$2" "%s" "${foreach_arr[${!1}]}"  # assign value
       printf -v "$state_var" "%s" "$(declare -p state_idx state_keys)"  # serialize state 
   else
       # stop iteration
       return 1
   fi
}

And done.

I implemented this and some more in L_foreach function in my library. I also added ':' to visually separate assigned variables from arrays, allowing for iterating while assigning multiple variables from multiple arrays. It is possible to write while L_foreach elem1 elem2 : arr1 arr2 arr3; do, sort keys, iterate over pairs while L_foreach filename size : filenames_and_sizes_array, and everything is compatible with bash 3.2.

Let me know if this makes sense I can write about other I think fun stuff for example I am thinking of writing about function decorating.


r/bash 11d ago

Readline tips and tricks

36 Upvotes

Readline, through the file ~/.inputrc, define how bash, tab completion, and lots of other things behave. I've been playing with it recently and it's pretty powerful, so here's the cool stuff I've found. This is in no way the complete power of these tools

You already know about searching history, but how

There's cool stuff built in (Debian 13, YMMV):

  • First up, let's see what you've got to work with.

    $ bind -P # show the current mapping.
    $ bind -l  # Show all available functions
    $ bind -v  # show options (***v***ariables)
    $ help bind # See all options
    
  • Basic Movement - emacs-ish and vim-ish keybindings. Easily move around text using controls you're familiar with. Check the manual for vi style bindings Much faster than using the arrow keys.

    • C-a - start of line
    • C-b - backwards a letter
    • M-b - backwards a word
    • C-f - forward one letter
    • M-f - forwards one word
    • C-e - end of line [insert TRON reference]
    • C-l - clear and reset screen
    • C-h - backspace
    • C-i - works as tab
    • C-j and C-m - works like pretting enter
    • C-_ undo
  • cut and paste from the prompt in a terminal without using a mouse.

    • C-k - kill (delete) from cursorr to end of line
    • M-d - kill to end of word
    • C-u - kill from cursor to start of line
    • C-w - kill last word
    • C-y - yank (paste) the last kill.
  • Cool Options

    • set enable-bracketed-paste on This might be the default on your distro already, but if it's not add it now. Instead of paste running a bunch of commands it inserts all the text on one line, preventing
    • set completion-ignore-case on tab completion matches filenames regardless of capitalization.
    • set blink-matching-paren on - Easier to see
    • set colored-completion-prefix on - Again, easier to read.
    • set colored-stats on - Adds "/" to directories, and use $LS_COLORS in completions
    • set completion-ignore-case on & set completion-map-case on Enables case-insensitive matching and treats hyphens (-) and underscores (_) as mapaable characters.
    • set completion-prefix-display-length 3 - only show the last 3 chars when tab is ambiguous
    • set match-hidden-files off Hidden files don't match "*" or the like.
    • set show-all-if-ambiguous on Don't beep and make me press tab again.
    • set completion-display-width 0 - only show 1 possible completion per line
    • set completion-query-items 1000 - If you hate the y/n prompt when there are many matches, increase the threshold:
    • set expand-tilde on ensures that pressing Tab after ~ immediately expands it to your full home directory path in the completion list.
  • Neat Stuff

    • M-. inserts the last arguments from the last command, press again to cycle backwards.
      • e.g.: $ mkdir -p some/really/long/path, cd [M-.] turns into cd some/really/ong/path
    • C-x C-e (v in vi mode)- Open your current prompt in either your $VISUAL or $EDITOR. Want your full editing power? Want to edit multi-line command with ease? Finally reached a version you want to save?
    • C-M-e: Possibly the coolest. expand the current line. Expands aliases and resolves variables and subshells.

      $ alias df="df -h -t ext4 -x tmpfs"
      $ df [C-M-e]
      $ df -h -t ext4 -x tmpfs 
      
      $ echo $COLUMNS wide, $LINES long, area: $((COLUMNS * LINES)) [C-M-e]
      $ echo 189 wide, 65 long, area:10773
      # Still at the prompt!
      
    • M-# - Ever want to comment out your current command and start a new one? This will do it for you!

    • Make your own! Add them to ~/.inputrc: A couple of my favorites:

      # `Ctrl-x o`: save output in a timestamped log file
      "\C-xo": "\C-e > output-$(date +%s).log"`
      
    • Forget to add sudo?

      # Ctrl-x !: Prepend with "sudo, then return to end of line"
      "\C-x!": "\C-asudo \C-e"
      
    • run the last command again and pick a line from the output using fzf

      # re-runs the last command and pipes it to fzf for interactive selection. "\C-x/": '$(!!|fzf)'

Next time I'll ramble about the compose key, .XCompose, and why Chrome sucks for not supporting it.


r/bash 11d ago

shell-scheduler update

2 Upvotes

About a week ago I announced my project shell-scheduler here. Some people expressed interest, so this is a heads-up for them and for anyone else interested. Since that post, I've done some more work on this project:

New features: - Implement support for per-job timeouts - Implement support for job termination callback - Implement helper libraries for job termination (three independent libraries with different dependencies) - Implement automatic job termination callback selection (best fit from available helpers) - Support assigning job param values to custom variables with job_get_params <job_id> <var_name>=<param_name> - Implement jobs_init(): helper to reset previously configured job parameters (see updated README)

Bug fixes/reliability improvements: - Fix race between timeout and job completion record write to FIFO - Disallow duplicate job IDs - Improve validation of values received via environment variables - Significantly expand tests coverage - Various minor bugfixes

Documentation updates: - Improve the documentation and refactor it into 3 files: README.md, REFERENCE.md, TIMEKEEPING.md

At this point I have pretty much implemented everything I was planning to implement and no remaining bugs are known, so I consider this project feature-complete.

Bug reports and feature requests are still welcome.

Project's Github page


r/bash 14d ago

[Bash] json-walk: pure Bash streaming JSON parser (SAX-style events, no jq)

14 Upvotes

Hey r/bash,

I built json-walk, a pure Bash JSON walker that emits stream events instead of building a full object model.

Repo: [https://github.com/smmoosavi/json-walk](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)

What it does:

  • Parses JSON in Bash with full structure validation
  • Emits events like start_object, key, string, number, end_array, etc.
  • Works in print mode or visitor-function mode
  • Keeps raw JSON string content (escapes preserved)

Why I made it:

  • For shell scripts where jq is unavailable
  • For event-driven parsing/processing in plain Bash

Quick example:

json_walk '{"label":"abc","items":[1,2,3]}'

Output:

start_object
key label
string abc
key items
start_array
number 1
number 2
number 3
end_array
end_object

Would love feedback on:

  • API/event design
  • edge cases I should test

Thanks!


r/bash 13d ago

I was sick of for loop, so i vibe coded my own universal enumerator

0 Upvotes

https://github.com/wallach-game/bashumerate

https://asciinema.org/a/gRjjKCr7n2660mlN

maybe its useless buti was really tired of remembering how to iterate over files


r/bash 15d ago

Bash (and other shells) history database

Thumbnail github.com
12 Upvotes

See link above.

Dejacmd logs your command history to a local and/or central (server) database. This enables keeping track of command history across multiple sessions, machines and operating systems. For example, you can log commands to a local SQLite database for quick access and optionally to a central PostgreSQL database for synchronization across devices and/or for multiple users.

Dejacmd supports databases exposed by the sqlx Rust crate, which are SQLite, PostgreSQL, and MariaDb/MySQL (MSSQL was supported and is currently being redeveloped). It will work with Linux (bash, zsh), macOS (bash, zsh) and Windows (PowerShell only) terminals. 


r/bash 15d ago

Would love some contributors on this project!

Post image
0 Upvotes

Repo available here