diff --git a/.config/shell/bin/cda b/.config/shell/bin/cda new file mode 100755 index 0000000..8dd841a --- /dev/null +++ b/.config/shell/bin/cda @@ -0,0 +1,16 @@ +#!/bin/bash + +# cd all: opens a new shell in each of the directories below the one you're in, so +# you can execute commands in them until you type 'exit' +# If I use this enough, I may make something that can do more +# Ideas for what it could do in the future: +# - somehow record typed commands so they can be automatically repeated like a macro +# - maybe get the length of the histfile before and after, executing the last X number of commands +# - Maybe just add an argument that takes a command and executes it in all dirs +# (although that wouldn't be as good as recording actions bc it's easy to do +# that by just writing a for loop) + +for DIR in *; do + (cd "$DIR" && zsh) +done + diff --git a/.config/shell/bin/cdf b/.config/shell/bin/cdf new file mode 100755 index 0000000..ed774ea --- /dev/null +++ b/.config/shell/bin/cdf @@ -0,0 +1,14 @@ +#!/bin/bash + +# cd find (interactive): cd to the containing dir of a file, or inside a folder, given part of its name +# Basically, an interactive version of what's above +# can take an `fd` command +# requires that `fzy` is installed + +DIR="$(fd $@ | fzy)" +if [ -f "$DIR" ];then + cd "$(dirname "$DIR")" && pwd +else + cd "$DIR" && pwd +fi + diff --git a/.config/shell/bin/cds b/.config/shell/bin/cds new file mode 100755 index 0000000..54d0fb2 --- /dev/null +++ b/.config/shell/bin/cds @@ -0,0 +1,18 @@ +#!/bin/bash + +# cd search: cd to a directory, given part of its name +# (also can take arguments for an `fd` commnd) +# (also can cd to a file if `-t f` is passed) + +if ! [ -z "$1" ];then + DIR="$(fd --max-results=1 -t d $@)" + if [ -f "$DIR" ];then + cd "$(dirname "$DIR")" && pwd + else + cd "$DIR" && pwd + fi +else + echo "$0: no arguments provided" + return 1 +fi + diff --git a/.config/shell/bin/chx b/.config/shell/bin/chx new file mode 100755 index 0000000..f5223a7 --- /dev/null +++ b/.config/shell/bin/chx @@ -0,0 +1,16 @@ +#!/bin/bash + +# toggles whether a file or group of files is executable + +for FILE in "$@";do + if [ -x "$FILE" ];then + chmod -x "$FILE" && + echo -e "$FILE: -x" + elif ! [ -x "$FILE" ];then + chmod +x "$FILE" && + echo -e "$FILE: +x" + else + echo "error: file $FILE does not exist" >&2 + fi +done + diff --git a/.config/shell/bin/ef b/.config/shell/bin/ef new file mode 100755 index 0000000..3b8f5e7 --- /dev/null +++ b/.config/shell/bin/ef @@ -0,0 +1,7 @@ +#!/bin/bash + +# edit file: Uses fzy to locate a file, and opens it in your favorite text editor +# Takes arguments for `fd` + +"$EDITOR" "$(fd $@ | fzy)" + diff --git a/.config/shell/bin/error b/.config/shell/bin/error new file mode 100755 index 0000000..20c25bb --- /dev/null +++ b/.config/shell/bin/error @@ -0,0 +1,8 @@ +#!/bin/bash + +# for sending error messages from functions and whatnot + +ERROR_CODE="$?" +>&2 echo "An error occurred within a function in the .zshrc on line number ${1}" +return $ERROR_CODE + diff --git a/.config/shell/bin/ex b/.config/shell/bin/ex new file mode 100755 index 0000000..5ec9f25 --- /dev/null +++ b/.config/shell/bin/ex @@ -0,0 +1,23 @@ +#!/bin/bash + +# Simple extraction script. Taken from manjaro's .bashrc + +if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xjf "$1" ;; + *.tar.gz) tar xzf "$1" ;; + *.bz2) bunzip2 "$1" ;; + *.rar) unrar x "$1" ;; + *.gz) gunzip "$1" ;; + *.tar) tar xf "$1" ;; + *.tbz2) tar xjf "$1" ;; + *.tgz) tar xzf "$1" ;; + *.zip) unzip "$1" ;; + *.Z) uncompress "$1";; + *.7z) 7z x "$1" ;; + *) echo "'$1' cannot be extracted via ex()" ;; + esac +else + echo "'$1' is not a valid file" +fi + diff --git a/.config/shell/bin/gloned b/.config/shell/bin/gloned new file mode 100755 index 0000000..5a82458 --- /dev/null +++ b/.config/shell/bin/gloned @@ -0,0 +1,12 @@ +#!/bin/bash + +# Git cLONE cD + +git clone "$1" || return $? +if ! cd "$(echo "$1" | sed 's/\.git//g' | rev | cut -d '/' -f 1 | rev)";then + echo 'Error: Could not `cd` into the repo' + return 1 +fi +echo +# ls --color=auto + diff --git a/.config/shell/bin/launch b/.config/shell/bin/launch new file mode 100755 index 0000000..41c72cd --- /dev/null +++ b/.config/shell/bin/launch @@ -0,0 +1,5 @@ +#!/bin/bash + +$@ > /dev/null 2>&1 & +disown + diff --git a/.config/shell/bin/mkswp b/.config/shell/bin/mkswp new file mode 100755 index 0000000..aa350f2 --- /dev/null +++ b/.config/shell/bin/mkswp @@ -0,0 +1,9 @@ +#!/bin/bash + +# Makes a swapfile at /swapfile of a given size (ex: mkswp 4G) + +sudo fallocate -l "$1" /swapfile && + sudo chmod 600 /swapfile +sudo mkswap /swapfile && + sudo swapon /swapfile + diff --git a/.config/shell/bin/prcolors b/.config/shell/bin/prcolors new file mode 100755 index 0000000..cb4d079 --- /dev/null +++ b/.config/shell/bin/prcolors @@ -0,0 +1,90 @@ +#!/bin/bash + +# prcolors: Display all colors in a few different ways >>> +# TODO: change this to make it not just a few scripts smashed together + +[ -z "$1" ] && 1=0 +if [ $1 -eq '1' ];then + # Taken from manjaro's bashrc >>> + local fgc bgc vals seq0 + + printf "Color escapes are %s\n" '\e[${value};...;${value}m' + printf "Values 30..37 are \e[33mforeground colors\e[m\n" + printf "Values 40..47 are \e[43mbackground colors\e[m\n" + printf "Value 1 gives a \e[1mbold-faced look\e[m\n\n" + + # foreground colors + for fgc in {30..37}; do + # background colors + for bgc in {40..47}; do + fgc=${fgc#37} # white + bgc=${bgc#40} # black + + vals="${fgc:+$fgc;}${bgc}" + vals=${vals%%;} + + seq0="${vals:+\e[${vals}m}" + printf " %-9s" "${seq0:-(default)}" + printf " ${seq0}TEXT\e[m" + printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m" + done + echo; echo + done + # <<< +elif [ $1 -eq '2' ];then + # from base16shell >>> + ansi_mappings=( + Red Green + Yellow Blue + Magenta Cyan + White Black + Bright_Red Bright_Green + Bright_Yellow Bright_Blue + Bright_Magenta Bright_Cyan + Bright_White Bright_Black + ) + colors=( + base00 base08 + base0B base0A + base0D base0E + base0C base05 + base03 base08 + base0B base0A + base0D base0E + base0C base07 + base09 base0F + base01 base02 + base04 base06 + ) + for padded_value in `seq -w 0 21`; do + color_variable="color${padded_value}" + eval current_color=\$${color_variable} + current_color=$(echo ${current_color//\//} | tr '[:lower:]' '[:upper:]') # get rid of slashes, and uppercase + non_padded_value=$((10#$padded_value)) + base16_color_name=${colors[$non_padded_value]} + current_color_label=${current_color:-unknown} + ansi_label=${ansi_mappings[$non_padded_value]} + block=$(printf "\x1b[48;5;${non_padded_value}m___________________________") + foreground=$(printf "\x1b[38;5;${non_padded_value}m$color_variable") + printf "%s %s %s %-30s %s\x1b[0m\n" $foreground $base16_color_name $current_color_label ${ansi_label:-""} $block + done; + #if [ $# -eq 1 ]; then + # printf "To restore current theme, source ~/.base16_theme or reopen your terminal\n" + #fi + # <<< +elif [ $1 -eq '3' ];then + # Similar to above, but does 256-bit colors. >>> + # Taken from this: https://github.com/romkatv/powerlevel10k#set-colors-through-Powerlevel10k-configuration-parameters + for i in {0..255}; do + print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'} + done + # <<< +else + cat <<-EOF + Usage: prcolors + 1: Manjaro bashrc -- for checking text readability + 2: base26shell -- for seeing the 16 set terminal colors + 3: 256 -- for testing 256 color output + EOF +fi + diff --git a/.config/shell/bin/rmswp b/.config/shell/bin/rmswp new file mode 100755 index 0000000..4ed9e4e --- /dev/null +++ b/.config/shell/bin/rmswp @@ -0,0 +1,6 @@ +#!/bin/bash + +# Deletes the swapfile created by mkswp() +sudo swapoff -v /swapfile +sudo rm /swapfile + diff --git a/.config/shell/bin/sitepath b/.config/shell/bin/sitepath new file mode 100755 index 0000000..cebd48b --- /dev/null +++ b/.config/shell/bin/sitepath @@ -0,0 +1,23 @@ +#!/bin/bash + +# TODO: encode the url to fix things like spaces using something like https://stackoverflow.com/a/10660730/11162605 +# usage: sitepath +# usage: sitepath +# usage: sitepath +# usage: sitepath -- you can search with 'fd' if you put in a command + + # account for if there is no urlencode command + URLENCODE=urlencode + if ! command -v urlencode > /dev/null 2>&1;then + URLENCODE=cat + fi + # If there is no input, make the input the current directory + [ -z ${1+x} ] && 1="$(pwd)" + FILEPATH="$(([ -e "$1" ] && readlink -f "$1") || fd $@ /home/blake/docker/blakenorth.net/site)" + + # change all file paths into urls + echo "$FILEPATH" | + grep -o 'site.*' | + sed 's+^site+https://blakenorth.net+g' | + $URLENCODE # if you need this, I am using dead10ck/urlencode (cargo install urlencode) + diff --git a/.config/shell/bin/todo b/.config/shell/bin/todo new file mode 100755 index 0000000..06173e8 --- /dev/null +++ b/.config/shell/bin/todo @@ -0,0 +1,40 @@ +#!/bin/bash + +# a simple way to manage your todo list +# Usage: +# todo -- pull latest repo version and edit ~/todo +# todo [any git command] -- manage todo for easy syncing, assuming ~/todo is +# a symlink that points to a file in a git repo +# +# Suggested use: make a git repo for holding your todo list, then make +# a symlink called 'todo' that points to your todo list in your home directory +# + +todo_dir="$(dirname "$(realpath ~/todo)")" +todo_file="$(realpath ~/todo)" +if [ -z "$@" ];then + ( # subshell to protect against directory changes + cd "$todo_dir" + + # pull the latest commits + git rev-parse && + git pull + + # open the file + "$EDITOR" "$todo_file" + + # commit and push the file if it's in a git repo and the file has changed + if git rev-parse && ! git diff --exit-code "$todo_file"; then + git commit "$todo_file" -m 'todo' && + git push + fi + ) + +elif [ "$@" = "cd" ]; then + cd "$todo_dir" + +else + git -C "$todo_dir" $@ + + fi +