zsh: almost all functions are scripts now (part 2)
This commit is contained in:
parent
75c3986785
commit
ec0cee28d9
14 changed files with 287 additions and 0 deletions
16
.config/shell/bin/cda
Executable file
16
.config/shell/bin/cda
Executable file
|
@ -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
|
||||||
|
|
14
.config/shell/bin/cdf
Executable file
14
.config/shell/bin/cdf
Executable file
|
@ -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
|
||||||
|
|
18
.config/shell/bin/cds
Executable file
18
.config/shell/bin/cds
Executable file
|
@ -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
|
||||||
|
|
16
.config/shell/bin/chx
Executable file
16
.config/shell/bin/chx
Executable file
|
@ -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
|
||||||
|
|
7
.config/shell/bin/ef
Executable file
7
.config/shell/bin/ef
Executable file
|
@ -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)"
|
||||||
|
|
8
.config/shell/bin/error
Executable file
8
.config/shell/bin/error
Executable file
|
@ -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
|
||||||
|
|
23
.config/shell/bin/ex
Executable file
23
.config/shell/bin/ex
Executable file
|
@ -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
|
||||||
|
|
12
.config/shell/bin/gloned
Executable file
12
.config/shell/bin/gloned
Executable file
|
@ -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
|
||||||
|
|
5
.config/shell/bin/launch
Executable file
5
.config/shell/bin/launch
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
$@ > /dev/null 2>&1 &
|
||||||
|
disown
|
||||||
|
|
9
.config/shell/bin/mkswp
Executable file
9
.config/shell/bin/mkswp
Executable file
|
@ -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
|
||||||
|
|
90
.config/shell/bin/prcolors
Executable file
90
.config/shell/bin/prcolors
Executable file
|
@ -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 <printing method number>
|
||||||
|
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
|
||||||
|
|
6
.config/shell/bin/rmswp
Executable file
6
.config/shell/bin/rmswp
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Deletes the swapfile created by mkswp()
|
||||||
|
sudo swapoff -v /swapfile
|
||||||
|
sudo rm /swapfile
|
||||||
|
|
23
.config/shell/bin/sitepath
Executable file
23
.config/shell/bin/sitepath
Executable file
|
@ -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 <path to file>
|
||||||
|
# usage: sitepath <file to find>
|
||||||
|
# usage: sitepath
|
||||||
|
# usage: sitepath <fd commands> -- 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)
|
||||||
|
|
40
.config/shell/bin/todo
Executable file
40
.config/shell/bin/todo
Executable file
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue