It can’t hurt to share some of you current helpers. Either someone else might get inspired by or in some cases you get suggestions how to make it better. Bash, Zsh, Fish or whatever shell script, command or alias (or abbreviation) you have, share here. Always fun to do so! I share mine in the comments, just like everybody else.
i use these 2 several times a day to back and forth between my work and personal laptop/workstation. (i can’t get the formatting right here on lemmy):
start_inputleap_tunnel() { mkdir -p ~/.inputleap AUTOSSH_GATETIME=0 nohup autossh -M 0 -N -R 24800:127.0.0.1:24800 \ -o TCPKeepAlive=yes \ -o ServerAliveInterval=15 \ -o ServerAliveCountMax=3 \ -o ExitOnForwardFailure=yes \ -o Compression=no \ -o IPQoS=throughput \ [email protected] > ~/.inputleap/autossh.log 2>&1 & disown nohup sh -c 'while true; do pkill -x input-leaps; /Applications/InputLeap.app/Contents/MacOS/input-leaps -f --config ~/.inputleap/synergy.conf --debug INFO --disable-crypto --name TS-eas-davcasta --address 127.0.0.1 >> ~/.inputleap/inputleaps.log 2>&1; sleep 2; done' >/dev/null 2>&1 & disown } start_inputleap_tunnel_reverse() { mkdir -p ~/.inputleap # 1. Start AutoSSH (AUTOSSH_GATETIME=0 prevents backoff delays on quick restarts) AUTOSSH_GATETIME=0 nohup autossh -M 0 -N -R 24800:127.0.0.1:24800 \ -o TCPKeepAlive=yes \ -o ServerAliveInterval=15 \ -o ServerAliveCountMax=3 \ -o ExitOnForwardFailure=yes \ -o Compression=no \ -o IPQoS=throughput \ [email protected] > ~/.inputleap/autossh.log 2>&1 & disown # 2. Start InputLeap server loop nohup sh -c 'while true; do pkill -x input-leaps; /Applications/InputLeap.app/Contents/MacOS/input-leaps -f --config ~/.inputleap/reverse-synergy.conf --debug INFO --disable-crypto --name TS-eas-davcasta --address 127.0.0.1 >> ~/.inputleap/inputleaps.log 2>&1; sleep 2; done' >/dev/null 2>&1 & disown } alias startleap=start_inputleap_tunnel alias startleapreverse=start_inputleap_tunnel_reverseInteresting. I can’t comment much about the commands itself, but want to quickly explain how to format. To start a code block, put 3 ticks in row like
```in one line. Everything after is a code block until 3 ticks end it. You can also set what type of (programming) language it is, for the coloring. Just addbashafter the 3 ticks in the opening block like```bash. That’s all to it. I don’t know hat languages are supported, but it works for Bash and Python in example. A full code block would be typed like this:```bash hello() { echo "Hello World!" } ```which is then rendered as
hello() { echo "Hello World!" }the ticks work and now you can see my badly formatted bash in all of it’s ugly glory. lol
thanks.
These are my favorite Bash functions:
#!/bin/bash alias ..="cd .." r() { # cd to git root cd "$(git rev-parse --show-toplevel 2>/dev/null)" } mkcd() { mkdir -p "$1" && cd "$1" } pwc() { # copy $PWD into Wayland clipboard with shell quoting printf '%q' "$PWD" | wl-copy } tmpdiff() { old="$(wl-paste)" read -n1 -srp "Copy new content into your clipboard, then press any key to diff it" diff <(echo "$old") <(wl-paste) } m() { # Opens man page and searches for an option. # Example: m cat -v MANPAGER="less -p '^\s+(?-i)$2'" man "$1" } grep_browser() { # Search file contents with ripgrep, then narrow it down using fzf with bat preview filename=$(rg --smart-case \ --line-number \ --with-filename \ --color=always \ --field-match-separator $'\u00a0' \ -- "$@" | fzf --delimiter $'\u00a0' \ --ansi \ --preview "bat --color=always {1} --highlight-line {2}" \ --preview-window 'up,~8,+{2}-5' | rg --only-matching '(.+)\u00a0(\d+)' --replace '$1:$2' --color=never) [ -n "$filename" ] && "$VISUAL" "$filename" }There is a bit to unpack here. I particularly like the
m()function here, to search for specific options in a man page. Thegrep_browser()is quiet involved and need to test it out myself. Meanwhile here is an “old” function of mine related to man pages, just searching all available pages, not their content:#!/bin/env bash # Lookup section meaning in `man man`. sections='1,8,6,5,7' show_manual () { man -- "${1%% *}" 2> /dev/null } export -f show_manual if selection=$(man -k . --sections="${sections}" \ | sort -t ' ' -k 2,2 -k 1,1 \ | fzf -q "${*}" \ --cycle \ --border=none \ --bind change:first \ --bind tab:down \ --bind shift-tab:up \ --bind esc:cancel+clear-selection \ --tiebreak=begin,chunk,length \ --reverse \ --preview='show_manual {}' \ --preview-window=down:70%:wrap:border-rounded) then show_manual "${selection}" fi
Aliases are great if you don’t want to break a habit after years.
alias yay=‘paru’
I stopped using search tools with file indexing, and needed an alternative. The classic
findcommand does a decent job and it has lot of options. But the regular usage is always a little bit awkward to me. So an alias is needed. However I like the abbreviations from Fish more, and installed zsh-abbr for Zsh for two reasons: a) I can edit the line before executing the abbr command, unlike with aliases or scripts, as it expands on typing, b) I can specify where the cursor lands after expansion.abbr "search"="find . -type d,f,l -iname '*#*'"The
#symbol is where the cursor lands and is used as search term. This command will simply search the current working directory.searchexpands tofind . -type d,f,l -iname '**'.The zsh-abbr plugin: https://zsh-abbr.olets.dev/ and my settings for it:
# zsh-abbr settings export ABBR_SET_EXPANSION_CURSOR=1 export ABBR_EXPANSION_CURSOR_MARKER='#' export ABBR_EXPERIMENTAL_COMMAND_POSITION_REGULAR_ABBREVIATIONS=2Running
set -o vior adding it to your bashrc gives your shell vi key bindings, which is one of my favorites.A good writeup: https://dev.to/brandonwallace/how-to-use-vim-mode-on-the-command-line-in-bash-fnn
I used to use Vi mode of Bash. But on Zsh I use an extension that goes beyond these bindings: https://github.com/jeffreytse/zsh-vi-mode
This is probably know to most but I found out in the most hilarious way that Ctrl-R in bash lets you search through past commands.
Someone was complaining about Ctrl-S not working in term-mode on emacs and Ctrl-R behaving weird in term-mode in emacs. So I looked at it myself and indeed it does! Well term-mode can be set in char-mode (every key-stroke except C-c is sent to the terminal immediately) vs line-mode (input is sent to the terminal only after hitting Enter, allowing for emacsy input editing before submission). Now in line-mode C-s and C-r work as they do in emacs, but then it hit me that the “weird” C-r search in char-mode must therefore be part of bash and sure enough it does the exact same thing in gnome-terminal as well lol.
I always forget about Ctrl-r and redescover it accidentally every time I press the key combo. I seem to like this combo a lot for some reason (Edit: maybe that’s because of my habits from using too much Vim, where Ctrl-r is used to redo something I undo). After typing a word you search for, pressing Ctrl-r will search for next occurrence BTW (at least in my setup).





