Use spaces instead of tabs

This commit is contained in:
ItsDrike 2021-12-18 18:07:47 +01:00
parent b07404d669
commit d843e90462
No known key found for this signature in database
GPG key ID: FB8CA11A2CF3A843
4 changed files with 134 additions and 138 deletions

View file

@ -37,22 +37,22 @@ alias vimdiff='nvim -d'
# Directory listing aliases, defaults to exa, if aviable
if command -v exa > /dev/null; then
alias ls='exa'
alias l='exa -glah --classify'
alias ll='exa -glah --classify -s=size --group-directories-first -r'
alias ldir='exa -glahD'
alias tree='exa -Tlagh'
alias dotall='exa -hulad .[a-z]*' # Show both dotdirs and dotfiles
alias dotfiles='dotall | grep -v ^d' # Show all dotfiles
alias dotdirs='dotall | grep --color=never ^d' # Show all dotdirs
alias ls='exa'
alias l='exa -glah --classify'
alias ll='exa -glah --classify -s=size --group-directories-first -r'
alias ldir='exa -glahD'
alias tree='exa -Tlagh'
alias dotall='exa -hulad .[a-z]*' # Show both dotdirs and dotfiles
alias dotfiles='dotall | grep -v ^d' # Show all dotfiles
alias dotdirs='dotall | grep --color=never ^d' # Show all dotdirs
else
alias ls='ls --color=auto'
alias l='ls -lahX --classify'
alias ll='ls -lahX --classify --group-directories-first'
alias ldir='ls -lahX --classify | grep --color=never ^d'
alias dotall='ls -lahXd .[a-z]*'
alias dotfiles='dotall | grep -v ^d'
alias dotdirs='dotall | grep --color=never ^d'
alias ls='ls --color=auto'
alias l='ls -lahX --classify'
alias ll='ls -lahX --classify --group-directories-first'
alias ldir='ls -lahX --classify | grep --color=never ^d'
alias dotall='ls -lahXd .[a-z]*'
alias dotfiles='dotall | grep -v ^d'
alias dotdirs='dotall | grep --color=never ^d'
fi
# Config access shortcuts
@ -252,16 +252,16 @@ alias rick='curl -s -L https://raw.githubusercontent.com/ItsDrike/rickrollrc/mas
# If user is not root, pass all commands via sudo/doas
if [ $UID -ne 0 ]; then
# Enable aliases to be sudoed/doased
# Enable aliases to be sudoed/doased
# with doas having precedence over sudo if found
## Uncomment if you are using autocompletion (is ZSH)
## Uncomment if you are using autocompletion (is ZSH)
#command -v /usr/bin/sudo > /dev/null && alias doas='nocorrect sudo ' && alias sudo='nocorrect sudo '
#command -v /usr/bin/doas > /dev/null && alias doas='nocorrect doas ' && alias sudo='nocorrect doas '
## if the above is uncommented, comment this
## if the above is uncommented, comment this
command -v /usr/bin/sudo > /dev/null && alias doas='sudo ' && alias sudo='sudo '
command -v /usr/bin/doas > /dev/null && alias doas='doas ' && alias sudo='doas '
command -v /usr/bin/doas > /dev/null && alias doas='doas ' && alias sudo='doas '
fi
# enable color support

View file

@ -2,22 +2,22 @@
# Show application listening on given port
function port() {
sudo netstat -pln | grep $1 | awk '{print $NF}'
sudo netstat -pln | grep $1 | awk '{print $NF}'
}
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
mkdir -p "$@" && cd "$_";
}
# `o` with no arguments opens the current directory, otherwise opens the given
# location
function o() {
if [ $# -eq 0 ]; then
open .;
else
open "$@";
fi;
if [ $# -eq 0 ]; then
open .;
else
open "$@";
fi;
}
# Use bat for nicer git diffs
@ -26,30 +26,28 @@ function batdiff() {
}
# Determine size of a file or total size of a directory
function dir-size() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
\du $arg -- "$@";
else
\du $arg .[^.]* ./*;
fi;
function dirsize() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$*" ]]; then
\du $arg -- "$@";
else
\du $arg .[^.]* ./*;
fi;
}
function randmac() {
sudo ip link set dev $1 down
sudo macchanger -A $1
sudo ip link set dev $1 up
sudo ip link set dev $1 down
sudo macchanger -A $1
sudo ip link set dev $1 up
}
# Go to the root of a git tree
cdgit () {
git rev-parse --is-inside-work-tree > /dev/null 2>&1
if [ $? -eq 0 ]; then
TEMP_PWD=`pwd`
if [ "$(git rev-parse --is-inside-work-tree > /dev/null 2>&1)" -eq 0 ]; then
while ! [ -d .git ]; do
cd ..
done
@ -161,36 +159,37 @@ fi
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
function targz() {
local tmpFile="${@%/}.tar";
tar -cvf "${tmpFile}" "${@}" || return 1;
# Combine given names spearated with spaces as the filename
local tmpFile="${@%/}.tar";
tar -cvf "${tmpFile}" "${@}" || return 1;
size=$(
stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
);
size=$(
stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
);
local cmd="";
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
# the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli";
else
if hash pigz 2> /dev/null; then
cmd="pigz";
else
cmd="gzip";
fi;
fi;
local cmd="";
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
# the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli";
else
if hash pigz 2> /dev/null; then
cmd="pigz";
else
cmd="gzip";
fi;
fi;
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
"${cmd}" -v "${tmpFile}" || return 1;
[ -f "${tmpFile}" ] && rm "${tmpFile}";
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
"${cmd}" -v "${tmpFile}" || return 1;
[ -f "${tmpFile}" ] && rm "${tmpFile}";
zippedSize=$(
stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `stat`
);
zippedSize=$(
stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `stat`
);
echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully.";
echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully.";
}
function anonymize {

View file

@ -1,43 +1,40 @@
#!/usr/bin/env bash
#!/bin/sh
if command -v pkgfile > /dev/null; then
# Command not found hook that uses `pkgfile` package
# to search through the package index in order to find
# a package which includes given command, which was resolved
# and not found, if there are no such packages, only print
# command not found message
command_not_found_handler() {
local pkgs cmd="$1" files=()
printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
files=(${(f)"$(pkgfile ${cmd})"})
if (( ${#files[@]} )); then
printf '\r%s may be found in the following packages:\n' "$cmd"
local res=() repo package version file
for file in "$files[@]"; do
res=("${(0)file}")
repo="$res[1]"
printf ' %s\n' "$repo"
done
else
printf '\n'
fi
return 127
}
elif [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
# Ubuntu handle for bash default command-not-found
# it works similarely to the above arch alternative,
# this is based on the original bash implementation
command_not_found_handler() {
# check because cmd not found could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
# Command not found hook that uses `pkgfile` package
# to search through the package index in order to find
# a package which includes given command, which was resolved
# and not found, if there are no such packages, only print
# command not found message
command_not_found_handler() {
cmd="$1"
printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
repos="$(pkgfile "$cmd")"
if [ -n "$repos" ]; then
printf '\r%s may be found in the following packages:\n' "$cmd"
echo "$repos" | while read -r pkg; do
printf ' %s\n' "$pkg"
done
else
printf '\n'
fi
return 127
}
elif [ -x /usr/lib/command-not-found ] || [ -x /usr/share/command-not-found/command-not-found ]; then
# Ubuntu handle for bash default command-not-found
# it works similarely to the above arch alternative,
# this is based on the original bash implementation
command_not_found_handler() {
# check because cmd not found could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
fi

View file

@ -30,20 +30,20 @@ export PROMPT_EOL_MARK=""
# (unless you change it in kernel), respect this and downgrade
# the color scheme accordingly (it won't look best, but it's
# still better than no colors)
if [ $TERM = "linux" ]; then
GREEN="%F{002}"
RED="%F{001}"
ORANGE="%F{003}"
BLUE="%F{004}"
LBLUE="%F{006}"
PURPLE="%F{005}"
if [ "$TERM" = "linux" ]; then
GREEN="%F{002}"
RED="%F{001}"
ORANGE="%F{003}"
BLUE="%F{004}"
LBLUE="%F{006}"
PURPLE="%F{005}"
else
GREEN="%F{047}"
RED="%F{196}"
ORANGE="%F{214}"
BLUE="%F{027}"
LBLUE="%F{075}"
PURPLE="%F{105}"
GREEN="%F{047}"
RED="%F{196}"
ORANGE="%F{214}"
BLUE="%F{027}"
LBLUE="%F{075}"
PURPLE="%F{105}"
fi
RESET="%f"
@ -52,34 +52,34 @@ git_prompt() {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
echo -n " $ORANGE${ref#refs/heads/}"
if [ ! -z "$(git status --short 2>/dev/null)" ]; then
if [ -n "$(git status --short 2>/dev/null)" ]; then
echo "$RED+"
fi
}
# Adds @chroot or @ssh
foreign_prompt() {
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
echo -n "@${ORANGE}chroot"
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
echo -n "@${ORANGE}ssh"
fi
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
echo -n "@${ORANGE}chroot"
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
echo -n "@${ORANGE}ssh"
fi
}
#nd Prints appropriate working directory
working_directory() {
# By default up to 5 directories will be tolerated before shortening
# After we surpass that, first directory (or ~) will be printed together with last 3
# This feature uses special symbol '…', but this isn't aviable when in TTY. Because
# of this, when we are in TTY, we fall back to longer '...'
# By default up to 5 directories will be tolerated before shortening
# After we surpass that, first directory (or ~) will be printed together with last 3
# This feature uses special symbol '…', but this isn't aviable when in TTY. Because
# of this, when we are in TTY, we fall back to longer '...'
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
echo -n " $BLUE$~"
elif [ $TERM = "linux" ]; then
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
else
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
fi
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
echo -n " $BLUE$~"
elif [ $TERM = "linux" ]; then
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
else
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
fi
}
# Execution time tracking hooks, this is unique to zsh, as it can add