zsh: realized some things need to be functions
By that, I mean things that change my working directory need to be functions
This commit is contained in:
parent
cba8e92e1d
commit
06ab216290
11 changed files with 93 additions and 94 deletions
|
@ -1,18 +0,0 @@
|
||||||
#!/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
|
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
# for sending error messages from functions and whatnot
|
# for sending error messages from functions and whatnot
|
||||||
|
|
||||||
ERROR_CODE="$?"
|
ERROR_CODE="$?"
|
||||||
>&2 echo "An error occurred within a function in the .zshrc on line number ${1}"
|
>&2 echo "$0: An error occurred on line number ${1}"
|
||||||
return $ERROR_CODE
|
return $ERROR_CODE
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# Simple extraction script. Taken from manjaro's .bashrc
|
# Simple extraction script. Taken from manjaro's .bashrc
|
||||||
|
|
||||||
if [ -f $1 ] ; then
|
if [ -f "$1" ] ; then
|
||||||
case $1 in
|
case $1 in
|
||||||
*.tar.bz2) tar xjf "$1" ;;
|
*.tar.bz2) tar xjf "$1" ;;
|
||||||
*.tar.gz) tar xzf "$1" ;;
|
*.tar.gz) tar xzf "$1" ;;
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Git cLONE cD
|
|
||||||
# Can take extra arguments for git (ex: gloned url:/repo folder)
|
|
||||||
|
|
||||||
# shellcheck disable=SC2068,SC2016
|
|
||||||
|
|
||||||
git clone $@ || 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
|
|
||||||
|
|
|
@ -6,18 +6,18 @@
|
||||||
# usage: sitepath
|
# usage: sitepath
|
||||||
# usage: sitepath <fd commands> -- you can search with 'fd' if you put in a command
|
# usage: sitepath <fd commands> -- you can search with 'fd' if you put in a command
|
||||||
|
|
||||||
# account for if there is no urlencode command
|
# account for if there is no urlencode command
|
||||||
URLENCODE=urlencode
|
URLENCODE=urlencode
|
||||||
if ! command -v urlencode > /dev/null 2>&1;then
|
if ! command -v urlencode > /dev/null 2>&1;then
|
||||||
URLENCODE=cat
|
URLENCODE=cat
|
||||||
fi
|
fi
|
||||||
# If there is no input, make the input the current directory
|
# If there is no input, make the input the current directory
|
||||||
[ -z ${1+x} ] && 1="$(pwd)"
|
[ -z ${1+x} ] && 1="$(pwd)"
|
||||||
FILEPATH="$(([ -e "$1" ] && readlink -f "$1") || fd $@ /home/blake/docker/blakenorth.net/site)"
|
FILEPATH="$(([ -e "$1" ] && readlink -f "$1") || fd $@ /home/blake/docker/blakenorth.net/site)"
|
||||||
|
|
||||||
# change all file paths into urls
|
# change all file paths into urls
|
||||||
echo "$FILEPATH" |
|
echo "$FILEPATH" |
|
||||||
grep -o 'site.*' |
|
grep -o 'site.*' |
|
||||||
sed 's+^site+https://blakenorth.net+g' |
|
sed 's+^site+https://blakenorth.net+g' |
|
||||||
$URLENCODE # if you need this, I am using dead10ck/urlencode (cargo install urlencode)
|
$URLENCODE # if you need this, I am using dead10ck/urlencode (cargo install urlencode)
|
||||||
|
|
||||||
|
|
8
.config/shell/bin/cda → .config/shell/functions/cda
Executable file → Normal file
8
.config/shell/bin/cda → .config/shell/functions/cda
Executable file → Normal file
|
@ -10,7 +10,9 @@
|
||||||
# (although that wouldn't be as good as recording actions bc it's easy to do
|
# (although that wouldn't be as good as recording actions bc it's easy to do
|
||||||
# that by just writing a for loop)
|
# that by just writing a for loop)
|
||||||
|
|
||||||
for DIR in *; do
|
cda() {
|
||||||
(cd "$DIR" && zsh)
|
for DIR in *; do
|
||||||
done
|
(cd "$DIR" && zsh)
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
16
.config/shell/bin/cdf → .config/shell/functions/cdf
Executable file → Normal file
16
.config/shell/bin/cdf → .config/shell/functions/cdf
Executable file → Normal file
|
@ -4,11 +4,11 @@
|
||||||
# Basically, an interactive version of what's above
|
# Basically, an interactive version of what's above
|
||||||
# can take an `fd` command
|
# can take an `fd` command
|
||||||
# requires that `fzy` is installed
|
# requires that `fzy` is installed
|
||||||
|
cdf() {
|
||||||
DIR="$(fd $@ | fzy)"
|
DIR="$(fd $@ | fzy)"
|
||||||
if [ -f "$DIR" ];then
|
if [ -f "$DIR" ];then
|
||||||
cd "$(dirname "$DIR")" && pwd
|
cd "$(dirname "$DIR")" && pwd
|
||||||
else
|
else
|
||||||
cd "$DIR" && pwd
|
cd "$DIR" && pwd
|
||||||
fi
|
fi
|
||||||
|
}
|
20
.config/shell/functions/cds
Normal file
20
.config/shell/functions/cds
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/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)
|
||||||
|
|
||||||
|
cds() {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
20
.config/shell/functions/gloned
Normal file
20
.config/shell/functions/gloned
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Git cLONE cD
|
||||||
|
# Can take extra arguments for git (ex: gloned url:/repo folder)
|
||||||
|
|
||||||
|
# shellcheck disable=SC2068,SC2016
|
||||||
|
|
||||||
|
gloned() {
|
||||||
|
# remove the url up to the last segment, and remove the .git from the end
|
||||||
|
REPO_DIR="${2:-"$(echo "${1%%.git}" | rev | cut -d '/' -f 1 | rev)"}"
|
||||||
|
|
||||||
|
git clone "$1" "$REPO_DIR" || exit $?
|
||||||
|
ls
|
||||||
|
if ! cd "$REPO_DIR";then
|
||||||
|
echo 'Error: Could not `cd` into the repo'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
# ls --color=auto
|
||||||
|
}
|
28
.config/shell/bin/todo → .config/shell/functions/todo
Executable file → Normal file
28
.config/shell/bin/todo → .config/shell/functions/todo
Executable file → Normal file
|
@ -9,12 +9,12 @@
|
||||||
# Suggested use: make a git repo for holding your todo list, then make
|
# 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
|
# a symlink called 'todo' that points to your todo list in your home directory
|
||||||
#
|
#
|
||||||
|
todo() {
|
||||||
todo_dir="$(dirname "$(realpath ~/todo)")"
|
todo_dir="$(dirname "$(realpath ~/todo)")"
|
||||||
todo_file="$(realpath ~/todo)"
|
todo_file="$(realpath ~/todo)"
|
||||||
if [ -z "$@" ];then
|
if [ -z "$*" ];then
|
||||||
( # subshell to protect against directory changes
|
( # subshell to protect against directory changes
|
||||||
cd "$todo_dir"
|
cd "$todo_dir" || exit
|
||||||
|
|
||||||
# pull the latest commits
|
# pull the latest commits
|
||||||
git rev-parse &&
|
git rev-parse &&
|
||||||
|
@ -28,13 +28,11 @@ if [ -z "$@" ];then
|
||||||
git commit "$todo_file" -m 'todo' &&
|
git commit "$todo_file" -m 'todo' &&
|
||||||
git push
|
git push
|
||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
|
|
||||||
elif [ "$@" = "cd" ]; then
|
|
||||||
cd "$todo_dir"
|
|
||||||
|
|
||||||
else
|
|
||||||
git -C "$todo_dir" $@
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
elif [ "$*" = "cd" ]; then
|
||||||
|
cd "$todo_dir" || exit
|
||||||
|
else
|
||||||
|
git -C "$todo_dir" $@
|
||||||
|
fi
|
||||||
|
}
|
32
.zshrc
32
.zshrc
|
@ -13,13 +13,14 @@
|
||||||
export EDITOR=vi
|
export EDITOR=vi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export PATH="$PATH:${XDG_DATA_HOME:-$HOME/.local/bin}:${XDG_CONFIG_HOME:-$HOME/.config/shell/bin}"
|
export PATH="$PATH:${XDG_DATA_HOME:-$HOME/.local}/bin:$SHELL_CONFIG_DIR/bin"
|
||||||
|
export SHELL_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/shell"
|
||||||
export SYSTEMD_EDITOR="$EDITOR"
|
export SYSTEMD_EDITOR="$EDITOR"
|
||||||
|
|
||||||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||||
export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh"
|
export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh"
|
||||||
|
|
||||||
export ZINIT_HOME_DIR="$HOME/.local/share/zinit"
|
export ZINIT_HOME_DIR="${XDG_DATA_HOME:-$HOME/.local}/share/zinit"
|
||||||
|
|
||||||
# Don't add extra space to the right side of the prompt
|
# Don't add extra space to the right side of the prompt
|
||||||
ZLE_RPROMPT_INDENT=0
|
ZLE_RPROMPT_INDENT=0
|
||||||
|
@ -45,7 +46,7 @@
|
||||||
# <<<
|
# <<<
|
||||||
|
|
||||||
# optionally source an external environment variable file
|
# optionally source an external environment variable file
|
||||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/envrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/envrc"
|
[ -f "$SHELL_CONFIG_DIR/shell/envrc" ] && source "$SHELL_CONFIG_DIR/shell/envrc"
|
||||||
}
|
}
|
||||||
# <<<
|
# <<<
|
||||||
### Aliases >>>
|
### Aliases >>>
|
||||||
|
@ -174,7 +175,7 @@
|
||||||
|
|
||||||
# <<<
|
# <<<
|
||||||
# optionally source an external alias file
|
# optionally source an external alias file
|
||||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc"
|
[ -f "$SHELL_CONFIG_DIR/shell/aliasrc" ] && source "$SHELL_CONFIG_DIR/shell/aliasrc"
|
||||||
}
|
}
|
||||||
|
|
||||||
# # TODO: remove all aliases that refrence programs which do not exist >>>
|
# # TODO: remove all aliases that refrence programs which do not exist >>>
|
||||||
|
@ -197,11 +198,13 @@
|
||||||
# <<<
|
# <<<
|
||||||
### Functions >>>
|
### Functions >>>
|
||||||
{
|
{
|
||||||
|
# grab all shell functions that are in files
|
||||||
|
source "$SHELL_CONFIG_DIR"/functions/*
|
||||||
|
|
||||||
# for sending error messages from functions and whatnot
|
# for sending error messages from functions and whatnot
|
||||||
error() {
|
error() {
|
||||||
ERROR_CODE="$?"
|
ERROR_CODE="$?"
|
||||||
>&2 echo "An error occurred within a function in the .zshrc on line number ${1}"
|
>&2 echo "(zshrc) An error occurred on line number ${1}"
|
||||||
return $ERROR_CODE
|
return $ERROR_CODE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,24 +214,13 @@
|
||||||
cd "$1" || error $LINENO
|
cd "$1" || error $LINENO
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
random-mac() {
|
|
||||||
interfaces=(enp5s0 wlp4s0)
|
|
||||||
for interface in "${interfaces[@]}";do
|
|
||||||
echo " Changing interface: $interface"
|
|
||||||
sudo ip link set dev $interface down
|
|
||||||
sudo macchanger -r $interface
|
|
||||||
sudo ip link set dev $interface up
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# believe it or not, zsh makes for a fine calculator
|
# believe it or not, zsh makes for a fine calculator
|
||||||
calc() {
|
calc() {
|
||||||
echo $(($*))
|
echo $(($*))
|
||||||
}
|
}
|
||||||
|
|
||||||
# optionally source an external function file
|
# optionally source an external function file
|
||||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/fnrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/fnrc"
|
[ -f "$SHELL_CONFIG_DIR/fnrc" ] && source "$SHELL_CONFIG_DIR/fnrc"
|
||||||
}
|
}
|
||||||
# <<<
|
# <<<
|
||||||
# <<<
|
# <<<
|
||||||
|
@ -290,9 +282,9 @@
|
||||||
|
|
||||||
## Themes
|
## Themes
|
||||||
# terminal colors
|
# terminal colors
|
||||||
if [[ -f ~/.config/shell/colors.sh ]];then
|
if [[ -f "$SHELL_CONFIG_DIR/shell/colors.sh" ]];then
|
||||||
# custom colors
|
# custom colors
|
||||||
source ~/.config/shell/colors.sh
|
source "$SHELL_CONFIG_DIR/shell/colors.sh"
|
||||||
else
|
else
|
||||||
# onedark shell colors
|
# onedark shell colors
|
||||||
zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh'
|
zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh'
|
||||||
|
@ -557,7 +549,7 @@ load_working_dir && cd - > /dev/null
|
||||||
# <<<
|
# <<<
|
||||||
|
|
||||||
# Optionally source the user's customized .zshrc
|
# Optionally source the user's customized .zshrc
|
||||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshrc.local" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshrc.local" || true
|
[ -f "$SHELL_CONFIG_DIR/zshrc.local" ] && source "$SHELL_CONFIG_DIR/zshrc.local" || true
|
||||||
|
|
||||||
# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3
|
# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue