Skip to content

Instantly share code, notes, and snippets.

View apolopena's full-sized avatar
💭
We live to learn!

Apolo Pena apolopena

💭
We live to learn!
View GitHub Profile
@apolopena
apolopena / capture-lolcat-raw-colors.md
Last active December 16, 2022 17:47
Capture a raw dump of lolcat colorized output (for a script or a command) that includes the ANSI escape sequences for the colors.

The Need

  • You need a raw dump of lolcat colorized output that includes the ANSI escape sequences for the colors.
  • You need this dump saved to a file.

The Solution

Pipe your output through lolcat, use the --force flag and then redirect the output to a file.

Examples

  1. Capture a raw dump of the output of a bash script piped through lolcat to the file colors.txt
  • bash my-script.sh | lolcat --force > colors.txt
@apolopena
apolopena / gitpod_gpg.sh
Last active February 4, 2022 20:47
Enable, configure and optionally trust a GPG key for signing git commits
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2022 Apolo Pena
#
# gitpod_gpg.sh
# Description:
# Enable, configure and optionally trust a GPG key for signing git commits
#
# Notes:
@apolopena
apolopena / badips.sh
Last active August 19, 2021 01:29
Dump or report on unauthorized server access attempts. Requires sudo.
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# File: badips.sh
# Author: Apolo Pena
# Description:
# Dumps a unique list of unauthorized ips to a file,
# or reports information to stdout about the unauthorized attempts
@apolopena
apolopena / tmux-named-sessions.sh
Created August 6, 2021 22:10
Creates new (or attaches to existing) tmux sessions using an '.icon' file. This script can be called from inside or outside of tmux
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# tmux-named-sessions.sh
# Description:
# Creates new tmux sessions using an '.icon' file
# The .icon file is an text file next to this script with an emoji in it
# This script can be called from inside or outside of tmux
@apolopena
apolopena / tmux-fortunes-poc.sh
Created August 6, 2021 20:15
tmux proof of concept for opening up a split pane window session with a series of synchronized commands
#!/bin/bash
#
# proof of concept: scripted tmux
# opens a 2 pane tmux session with rainbows fortunes
# marks the window status red because the panes are synchronized
# and then closes it all down
main() {
tmux new-session \;\
setw -g window-status-current-format '#{?pane_synchronized,#[bg=red],}#I:#W' \;\
@apolopena
apolopena / new-repo-from-repo.sh
Last active February 4, 2022 21:26
Create a new repository from an existing repository. Wipes out git history.
# shellcheck shell=bash
# shellcheck disable=2001
#
# If using this as zsh function snippet, remove the .sh file extension
#
# Creates a new repository from an existing repository
# All git history is removed
# $1: git url of the original repository to use to create a new repository from
# $2: name of the new repository including the github user name. This repository must already exist in github.
# For example: apolopena/gitpod-laravel-starter
@apolopena
apolopena / new-repo-from-branch.sh
Last active February 4, 2022 21:34
Create a new repository from the branch of an existing one. Wipe out git history.
# shellcheck shell=bash
# shellcheck disable=2001
#
# If using this as zsh function snippet, remove the .sh file extension
# Creates a new repository from the branch of an existing repository
# All git history is removed
# $1: git url of the original repository to use to create a new repository from
# $2: branch name of the original repository to use
# $3: name of the new repository including the github user name. This repository must already exist in github.
@apolopena
apolopena / new-lgs-from-branch
Last active April 23, 2021 15:57
zsh function snippet to setup a local and remote github repository from a branch using `gitpod-laravel-starter` as the starting point
# zsh function snippet
#
# Creates a new project from a branch of the repo https://github.com/apolopena/gitpod-laravel8-starter
# Assumes that you already have a blank repo for this project created in your github account
# Assumes that you want to use https instead of ssh
# $1: branch name to clone from
# $2: new repo name to clone into and push to remote (the default branch will be called main)
# new repo name must match the name of the blank repo you have created in github for this project.
# $3: GitHub username
@apolopena
apolopena / new-lgs
Last active April 23, 2021 15:57
zsh function snippet to setup a local and remote github repository using `gitpod-laravel-starter` as the starting point
# zsh function snippet
#
# Creates a new project from the repo https://github.com/apolopena/gitpod-laravel8-starter
# Assumes that you already have a blank repo created for this new project in your github account
# Assumes that you want to use https instead of ssh
# $1: new repo name to clone into and push to remote (the default branch will be called main)
# $2: GitHub username
# new repo name must match the name of the blank repo you have created in github for this project.
__new_repo_project_name="$1"; __github_username="$2"; mkdir "$__new_repo_project_name" && cd "$__new_repo_project_name" && git clone https://github.com/apolopena/gitpod-laravel8-starter.git . && rm -rf .git && git init && git add -A && git commit -m "initial commit built from https://github.com/apolopena/gitpod-laravel8-starter" && git remote add origin "https://github.com/$__github_username/$__new_repo_project_name.git" && git branch -m main && git push -u origin main
@apolopena
apolopena / new-lgs.sh
Last active April 23, 2021 15:47
Sets up local and remote github repositories using `gitpod-laravel-starter` as the starting point.
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# new-lgs.sh
# Description:
# Sets up a new project repository locally and remotely using gitpod-laravel-starter as the starting point.
# For use in your .bashrc, .bash_profile etc.. You may copy the functions and leave out the licensing.
# Functions from this script can also be called directly using your bash interpreter: