mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-12-26 13:14:35 +00:00
Use spaces instead of tabs
This commit is contained in:
parent
b07404d669
commit
d843e90462
|
@ -37,22 +37,22 @@ alias vimdiff='nvim -d'
|
||||||
|
|
||||||
# Directory listing aliases, defaults to exa, if aviable
|
# Directory listing aliases, defaults to exa, if aviable
|
||||||
if command -v exa > /dev/null; then
|
if command -v exa > /dev/null; then
|
||||||
alias ls='exa'
|
alias ls='exa'
|
||||||
alias l='exa -glah --classify'
|
alias l='exa -glah --classify'
|
||||||
alias ll='exa -glah --classify -s=size --group-directories-first -r'
|
alias ll='exa -glah --classify -s=size --group-directories-first -r'
|
||||||
alias ldir='exa -glahD'
|
alias ldir='exa -glahD'
|
||||||
alias tree='exa -Tlagh'
|
alias tree='exa -Tlagh'
|
||||||
alias dotall='exa -hulad .[a-z]*' # Show both dotdirs and dotfiles
|
alias dotall='exa -hulad .[a-z]*' # Show both dotdirs and dotfiles
|
||||||
alias dotfiles='dotall | grep -v ^d' # Show all dotfiles
|
alias dotfiles='dotall | grep -v ^d' # Show all dotfiles
|
||||||
alias dotdirs='dotall | grep --color=never ^d' # Show all dotdirs
|
alias dotdirs='dotall | grep --color=never ^d' # Show all dotdirs
|
||||||
else
|
else
|
||||||
alias ls='ls --color=auto'
|
alias ls='ls --color=auto'
|
||||||
alias l='ls -lahX --classify'
|
alias l='ls -lahX --classify'
|
||||||
alias ll='ls -lahX --classify --group-directories-first'
|
alias ll='ls -lahX --classify --group-directories-first'
|
||||||
alias ldir='ls -lahX --classify | grep --color=never ^d'
|
alias ldir='ls -lahX --classify | grep --color=never ^d'
|
||||||
alias dotall='ls -lahXd .[a-z]*'
|
alias dotall='ls -lahXd .[a-z]*'
|
||||||
alias dotfiles='dotall | grep -v ^d'
|
alias dotfiles='dotall | grep -v ^d'
|
||||||
alias dotdirs='dotall | grep --color=never ^d'
|
alias dotdirs='dotall | grep --color=never ^d'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Config access shortcuts
|
# 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 user is not root, pass all commands via sudo/doas
|
||||||
if [ $UID -ne 0 ]; then
|
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
|
# 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/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 '
|
#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/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
|
fi
|
||||||
|
|
||||||
# enable color support
|
# enable color support
|
||||||
|
|
|
@ -2,22 +2,22 @@
|
||||||
|
|
||||||
# Show application listening on given port
|
# Show application listening on given port
|
||||||
function 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
|
# Create a new directory and enter it
|
||||||
function mkd() {
|
function mkd() {
|
||||||
mkdir -p "$@" && cd "$_";
|
mkdir -p "$@" && cd "$_";
|
||||||
}
|
}
|
||||||
|
|
||||||
# `o` with no arguments opens the current directory, otherwise opens the given
|
# `o` with no arguments opens the current directory, otherwise opens the given
|
||||||
# location
|
# location
|
||||||
function o() {
|
function o() {
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
open .;
|
open .;
|
||||||
else
|
else
|
||||||
open "$@";
|
open "$@";
|
||||||
fi;
|
fi;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use bat for nicer git diffs
|
# Use bat for nicer git diffs
|
||||||
|
@ -26,30 +26,28 @@ function batdiff() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine size of a file or total size of a directory
|
# Determine size of a file or total size of a directory
|
||||||
function dir-size() {
|
function dirsize() {
|
||||||
if du -b /dev/null > /dev/null 2>&1; then
|
if du -b /dev/null > /dev/null 2>&1; then
|
||||||
local arg=-sbh;
|
local arg=-sbh;
|
||||||
else
|
else
|
||||||
local arg=-sh;
|
local arg=-sh;
|
||||||
fi
|
fi
|
||||||
if [[ -n "$@" ]]; then
|
if [[ -n "$*" ]]; then
|
||||||
\du $arg -- "$@";
|
\du $arg -- "$@";
|
||||||
else
|
else
|
||||||
\du $arg .[^.]* ./*;
|
\du $arg .[^.]* ./*;
|
||||||
fi;
|
fi;
|
||||||
}
|
}
|
||||||
|
|
||||||
function randmac() {
|
function randmac() {
|
||||||
sudo ip link set dev $1 down
|
sudo ip link set dev $1 down
|
||||||
sudo macchanger -A $1
|
sudo macchanger -A $1
|
||||||
sudo ip link set dev $1 up
|
sudo ip link set dev $1 up
|
||||||
}
|
}
|
||||||
|
|
||||||
# Go to the root of a git tree
|
# Go to the root of a git tree
|
||||||
cdgit () {
|
cdgit () {
|
||||||
git rev-parse --is-inside-work-tree > /dev/null 2>&1
|
if [ "$(git rev-parse --is-inside-work-tree > /dev/null 2>&1)" -eq 0 ]; then
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
TEMP_PWD=`pwd`
|
|
||||||
while ! [ -d .git ]; do
|
while ! [ -d .git ]; do
|
||||||
cd ..
|
cd ..
|
||||||
done
|
done
|
||||||
|
@ -161,36 +159,37 @@ fi
|
||||||
|
|
||||||
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
|
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
|
||||||
function targz() {
|
function targz() {
|
||||||
local tmpFile="${@%/}.tar";
|
# Combine given names spearated with spaces as the filename
|
||||||
tar -cvf "${tmpFile}" "${@}" || return 1;
|
local tmpFile="${@%/}.tar";
|
||||||
|
tar -cvf "${tmpFile}" "${@}" || return 1;
|
||||||
|
|
||||||
size=$(
|
size=$(
|
||||||
stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
|
stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
|
||||||
stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
|
stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
|
||||||
);
|
);
|
||||||
|
|
||||||
local cmd="";
|
local cmd="";
|
||||||
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
|
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
|
||||||
# the .tar file is smaller than 50 MB and Zopfli is available; use it
|
# the .tar file is smaller than 50 MB and Zopfli is available; use it
|
||||||
cmd="zopfli";
|
cmd="zopfli";
|
||||||
else
|
else
|
||||||
if hash pigz 2> /dev/null; then
|
if hash pigz 2> /dev/null; then
|
||||||
cmd="pigz";
|
cmd="pigz";
|
||||||
else
|
else
|
||||||
cmd="gzip";
|
cmd="gzip";
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
|
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
|
||||||
"${cmd}" -v "${tmpFile}" || return 1;
|
"${cmd}" -v "${tmpFile}" || return 1;
|
||||||
[ -f "${tmpFile}" ] && rm "${tmpFile}";
|
[ -f "${tmpFile}" ] && rm "${tmpFile}";
|
||||||
|
|
||||||
zippedSize=$(
|
zippedSize=$(
|
||||||
stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
|
stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
|
||||||
stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `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 {
|
function anonymize {
|
||||||
|
|
|
@ -1,43 +1,40 @@
|
||||||
#!/usr/bin/env bash
|
#!/bin/sh
|
||||||
|
|
||||||
if command -v pkgfile > /dev/null; then
|
if command -v pkgfile > /dev/null; then
|
||||||
# Command not found hook that uses `pkgfile` package
|
# Command not found hook that uses `pkgfile` package
|
||||||
# to search through the package index in order to find
|
# to search through the package index in order to find
|
||||||
# a package which includes given command, which was resolved
|
# a package which includes given command, which was resolved
|
||||||
# and not found, if there are no such packages, only print
|
# and not found, if there are no such packages, only print
|
||||||
# command not found message
|
# command not found message
|
||||||
command_not_found_handler() {
|
command_not_found_handler() {
|
||||||
local pkgs cmd="$1" files=()
|
cmd="$1"
|
||||||
printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
|
printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
|
||||||
files=(${(f)"$(pkgfile ${cmd})"})
|
repos="$(pkgfile "$cmd")"
|
||||||
if (( ${#files[@]} )); then
|
if [ -n "$repos" ]; then
|
||||||
printf '\r%s may be found in the following packages:\n' "$cmd"
|
printf '\r%s may be found in the following packages:\n' "$cmd"
|
||||||
local res=() repo package version file
|
echo "$repos" | while read -r pkg; do
|
||||||
for file in "$files[@]"; do
|
printf ' %s\n' "$pkg"
|
||||||
res=("${(0)file}")
|
done
|
||||||
repo="$res[1]"
|
else
|
||||||
printf ' %s\n' "$repo"
|
printf '\n'
|
||||||
done
|
fi
|
||||||
else
|
return 127
|
||||||
printf '\n'
|
}
|
||||||
fi
|
elif [ -x /usr/lib/command-not-found ] || [ -x /usr/share/command-not-found/command-not-found ]; then
|
||||||
return 127
|
# Ubuntu handle for bash default command-not-found
|
||||||
}
|
# it works similarely to the above arch alternative,
|
||||||
elif [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
|
# this is based on the original bash implementation
|
||||||
# Ubuntu handle for bash default command-not-found
|
command_not_found_handler() {
|
||||||
# it works similarely to the above arch alternative,
|
# check because cmd not found could've been removed in the meantime
|
||||||
# this is based on the original bash implementation
|
if [ -x /usr/lib/command-not-found ]; then
|
||||||
command_not_found_handler() {
|
/usr/lib/command-not-found -- "$1"
|
||||||
# check because cmd not found could've been removed in the meantime
|
return $?
|
||||||
if [ -x /usr/lib/command-not-found ]; then
|
elif [ -x /usr/share/command-not-found/command-not-found ]; then
|
||||||
/usr/lib/command-not-found -- "$1"
|
/usr/share/command-not-found/command-not-found -- "$1"
|
||||||
return $?
|
return $?
|
||||||
elif [ -x /usr/share/command-not-found/command-not-found ]; then
|
else
|
||||||
/usr/share/command-not-found/command-not-found -- "$1"
|
printf "%s: command not found\n" "$1" >&2
|
||||||
return $?
|
return 127
|
||||||
else
|
fi
|
||||||
printf "%s: command not found\n" "$1" >&2
|
}
|
||||||
return 127
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -30,20 +30,20 @@ export PROMPT_EOL_MARK=""
|
||||||
# (unless you change it in kernel), respect this and downgrade
|
# (unless you change it in kernel), respect this and downgrade
|
||||||
# the color scheme accordingly (it won't look best, but it's
|
# the color scheme accordingly (it won't look best, but it's
|
||||||
# still better than no colors)
|
# still better than no colors)
|
||||||
if [ $TERM = "linux" ]; then
|
if [ "$TERM" = "linux" ]; then
|
||||||
GREEN="%F{002}"
|
GREEN="%F{002}"
|
||||||
RED="%F{001}"
|
RED="%F{001}"
|
||||||
ORANGE="%F{003}"
|
ORANGE="%F{003}"
|
||||||
BLUE="%F{004}"
|
BLUE="%F{004}"
|
||||||
LBLUE="%F{006}"
|
LBLUE="%F{006}"
|
||||||
PURPLE="%F{005}"
|
PURPLE="%F{005}"
|
||||||
else
|
else
|
||||||
GREEN="%F{047}"
|
GREEN="%F{047}"
|
||||||
RED="%F{196}"
|
RED="%F{196}"
|
||||||
ORANGE="%F{214}"
|
ORANGE="%F{214}"
|
||||||
BLUE="%F{027}"
|
BLUE="%F{027}"
|
||||||
LBLUE="%F{075}"
|
LBLUE="%F{075}"
|
||||||
PURPLE="%F{105}"
|
PURPLE="%F{105}"
|
||||||
fi
|
fi
|
||||||
RESET="%f"
|
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
|
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/}"
|
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+"
|
echo "$RED+"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Adds @chroot or @ssh
|
# Adds @chroot or @ssh
|
||||||
foreign_prompt() {
|
foreign_prompt() {
|
||||||
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
|
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
|
||||||
echo -n "@${ORANGE}chroot"
|
echo -n "@${ORANGE}chroot"
|
||||||
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||||
echo -n "@${ORANGE}ssh"
|
echo -n "@${ORANGE}ssh"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#nd Prints appropriate working directory
|
#nd Prints appropriate working directory
|
||||||
working_directory() {
|
working_directory() {
|
||||||
# By default up to 5 directories will be tolerated before shortening
|
# 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
|
# 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
|
# 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 '...'
|
# of this, when we are in TTY, we fall back to longer '...'
|
||||||
|
|
||||||
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
|
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
|
||||||
echo -n " $BLUE$~"
|
echo -n " $BLUE$~"
|
||||||
elif [ $TERM = "linux" ]; then
|
elif [ $TERM = "linux" ]; then
|
||||||
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
|
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
|
||||||
else
|
else
|
||||||
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
|
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execution time tracking hooks, this is unique to zsh, as it can add
|
# Execution time tracking hooks, this is unique to zsh, as it can add
|
||||||
|
|
Loading…
Reference in a new issue