Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
sebastiancarlos / custom-locate.bash
Last active August 23, 2023 11:52
locate is great, but you can make it faster with a custom updatedb
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/watch?v=KFtZbsSG_fA
# add this to your ~/.bashrc or something like that
# alias for every locate database
alias locate="glocate --regextype=posix-extended --database=${HOME}/tmp/locatedb-min"
alias locatehome="glocate --regextype=posix-extended --database=${HOME}/tmp/locatedb-home"
alias locateall="glocate --regextype=posix-extended --database=${HOME}/tmp/locatedb"
@sebastiancarlos
sebastiancarlos / poor-mans-ripgrep.sh
Last active July 31, 2023 19:28
poor-mans-ripgrep.sh - ripgrep for those stuck with grep
# All my gist code is licensed under the terms of the MIT license.
# poor-man's ripgrep
# - like grep, but ignore hidden files and folders (prefixed with a dot) and
# node_modules.
# - because grep's --exclude-dir only matches top-level directories, we need to
# use find
# - last argument is starting point. It must be provided, otherwise it's tricky
# to distinguish it from the pattern
# - any previous arguments are passed to grep before the matching files,
@sebastiancarlos
sebastiancarlos / toggle_jobs.bash
Last active October 23, 2024 19:25
Toggle between the last two jobs in Bash by pressing "Ctrl-Z Ctrl-Z" (Or toggle between the shell and your single job by pressing "Ctrl-Z")
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/0zx4uSBUt_k
# Add this somewhere in your ~/.bashrc
# Use bash-preexec.sh (https://github.com/rcaloras/bash-preexec) to:
# - disable the Ctrl-Z keybinding before printing the prompt
# - enable the Ctrl-Z keybinding before executing a command
#
@sebastiancarlos
sebastiancarlos / commands.sh
Last active December 15, 2024 18:41
commands - list all commands in your PATH, and their directories
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/9sKEQ-DFL8I
# commands
# - list all commands in your PATH, and their directories
function commands () {
local green='\x1b[32m'
local reset='\x1b[0m'
@sebastiancarlos
sebastiancarlos / vi.inputrc
Last active May 3, 2024 18:10
Add vi mode to your Bash prompt.
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/7IEfnUqjaSk
# add the contents of this file to ~/.inputrc
# this is where the magic happens
set editing-mode vi
# vi INSERT prompt
@sebastiancarlos
sebastiancarlos / bash-killring-viewer.sh
Last active August 23, 2023 11:58
Bash killring visualizer - Script to view the killring in Bash
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/watch?v=Yat95AAV5k4
# from https://unix.stackexchange.com/a/217390/569343
# write provided text to the terminal input
# (does not work in subshells)
# - There are some weird errors when I remove the 2>/dev/nulls, but I don't
# even know how to begin to fix them.
function write_to_input () {
@sebastiancarlos
sebastiancarlos / color-kill.bash
Last active August 23, 2023 12:00
custom "kill -l" with color output and better column formatting
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/cZIxuQuY7RE
# custom kill -l
# - column format and color the texts after SIG
# - add some descriptions
function kill () {
local green='\x1b[32m'
local bold='\x1b[1m'
@sebastiancarlos
sebastiancarlos / silence-autocd.sh
Last active November 15, 2024 07:55
Hack to suppress the default output of autocd in Bash.
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/ojhaUNYetsU
shopt -s autocd
# silence_autocd
# - Hack to stop autocd from printing the directory after autocd'ing.
# - Unfortunately there is no clean way to do this except messing with
# BASH_XTRACEFD, a poorly understood file descriptor that we are better not
@sebastiancarlos
sebastiancarlos / custom-declare.sh
Last active August 23, 2023 12:02
Custom version of "declare -F" with filename and line number.
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/q26DJ5qOXxM
# custom declare -F
# - add filename and table output to "declare -F"
# - this is based on the "declare -F name" output when shopt extdebug is on
function declare () {
if [[ $# == 1 && "$1" == "-F" ]]; then
shopt -s extdebug
@sebastiancarlos
sebastiancarlos / color-bind.sh
Last active August 23, 2023 12:03
Custom version of "bind -V" and "bind -P" with table output and color
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/9dU44VdoGIo
# custom bind
# - color and table formatting for "-V" and "-P"
# - if using vi mode, print both "normal" and "insert" keybindings
# - print keybindings for all keymaps if "-a" is present
function bind () {
if [[ "$#" == 1 && "$1" == "-V" ]]; then