Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
sebastiancarlos / term2plain.bash
Last active January 23, 2024 10:49
term2plain - Record an interactive terminal session, and convert it to plain text.
#! /usr/bin/env bash
# All my gist code is licensed under the MIT license.
# term2plain
# - Convert a text file containing terminal escape sequences to plain text.
# - This plain text is close to the visual result of running the file in a
# terminal.
# - This is achieved by running the file in a virtual terminal (tmux) and
# capturing it's buffer output.
@sebastiancarlos
sebastiancarlos / colorcat.bash
Last active October 19, 2023 04:07
Cross-app URL aliases (like shell aliases) powered by Nginx.
#!/usr/bin/env bash
# All my gist code is licensed under the MIT license.
# Video demo: https://www.youtube.com/watch?v=y542zPAPeG4
# colorcat
# - cats a file, but if any line contains N hex colors, it appends the colors
# (rendered as ansi escape sequences) to the end of the line.
# - input can be stdin, a file, or a hex color in plain text
@sebastiancarlos
sebastiancarlos / fonts.bash
Last active September 25, 2023 05:28
Check your OS fonts from your terminal
#!/usr/bin/env bash
# Video demo: N/A (This script is so dank that YouTube took down my video without explanation)
# Add this to your ~/.bashrc
# custom fc-list
# - sort list
# - add color
# - format table output
@sebastiancarlos
sebastiancarlos / custom-type.bash
Last active August 23, 2023 11:48
Custom version of the Bash 'type' command, navigating symlinks and aliases.
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/mYfEIZFlIwo
# Put this in your .bashrc or something like that
# pretty_print_directory
# - replace $HOME with ~
# - make everything before the last '/' green, and everything after white and
# bold
@sebastiancarlos
sebastiancarlos / show_notifications.bash
Last active December 29, 2023 01:06
Show notifications in your terminal
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/WVyqVkGYb4k
# Add this somewhere in ~/.bashrc
# write_message
# - write a message on the lower right corner of the terminal
function write_message () {
if [[ "$#" -eq 0 ]]; then
@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 / grepdist.sh
Last active August 5, 2023 13:57
Grepdist - Print the number of matches in each 10% section of a file
#!/usr/bin/env bash
# All my gist code is licensed under the terms of the MIT license.
# GREPDIST
# Print the number of matches in each 10% section of the file
#
# Example with grep:
# $ grep -c 'Napoleon' war_and_peace.txt
# 576
@thingsiplay
thingsiplay / save ()
Last active May 31, 2023 11:06
save - Capture and reuse output of command (Bash function)
# save - Capture and reuse output of command
# A Bash function
#
# usage: save [file]
#
# On start of the Bash session a new temporary file is created that lives as
# long as this terminal session lives. This is the default file. It's path can
# be looked up in the environmental variable $SAVE. Anytime `save` runs, it
# will lookup this variable. The first argument to `save` is a file path that
# will be used as $SAVE file. A manual set file won't be deleted automatically.
@papes1ns
papes1ns / dexec.sh
Created May 17, 2023 02:15
dexec.sh
#!/usr/bin/env bash
set -eu # do not proceed on error
if [ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF
Quick command to get a shell inside a running docker container.
Usage: dexec [container_name] [command]
@jojomak13
jojomak13 / select2.blade.php
Last active April 13, 2024 22:05
select2 input with alpinejs and livewire
@props(['multiple' => false])
<div {{ $attributes }} wire:ignore x-data="{
value: @entangle($attributes->wire('model')),
init(){
let input = new TomSelect(this.$refs.select, {
onChange: (value) => this.value = value,
items: this.value
});
}