mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-06-29 20:20:41 +00:00
Add dotfiles
This commit is contained in:
commit
02565d76fc
12 changed files with 1802 additions and 0 deletions
117
home/.config/sh/aliases
Executable file
117
home/.config/sh/aliases
Executable file
|
@ -0,0 +1,117 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# enable color support
|
||||
if [ -x /usr/bin/dircolors ]; then
|
||||
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
||||
alias dir='dir --color=auto'
|
||||
alias vdir='vdir --color=auto'
|
||||
|
||||
alias grep='grep --color=auto'
|
||||
alias cgrep='grep --color=always'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
fi
|
||||
|
||||
# Exa aliases (replacement for ls, if you are using ls, comment or change this
|
||||
alias ls='exa'
|
||||
alias ll='exa -glah'
|
||||
alias ld='exa -glahD'
|
||||
alias lt='exa -Tlagh'
|
||||
alias tree='exa -T'
|
||||
alias dotfiles='exa -hula -d .[a-z]* | grep -v ^d' # Show all dotfiles
|
||||
alias dotdirs='exa -hulaD -d .[a-z]*' # Show all dotdirs
|
||||
alias dotall='exa -hula -d .[a-z]*' # Show both dotdirs and dotfiles
|
||||
|
||||
# Shortcuts
|
||||
alias vi='vim'
|
||||
alias rr='rm -r'
|
||||
alias sv='systemctl'
|
||||
|
||||
# Changing directories
|
||||
alias ..='cd ..'
|
||||
alias ...='cd ../../'
|
||||
alias ....='cd ../../../'
|
||||
alias .....='cd ../../../../'
|
||||
alias .2='cd ../../'
|
||||
alias .3='cd ../../../'
|
||||
alias .4='cd ../../../../'
|
||||
alias .5='cd ../../../../../'
|
||||
|
||||
# Python
|
||||
alias py3='python3'
|
||||
alias py2='python2'
|
||||
alias py='ipython'
|
||||
alias ipy='ipython'
|
||||
alias bpy='bpython'
|
||||
|
||||
# Config access shortcuts
|
||||
alias cfzshrc='vim ~/.zshrc'
|
||||
alias cfvim='vim ~/.config/vim/vimrc'
|
||||
alias cfalias='vim ~/.config/sh/aliases'
|
||||
|
||||
# Replacements
|
||||
alias du='du -ach | sort -h' # Sort du by size
|
||||
alias mkdir='mkdir -p' # Mkdir with automatic creation of parent directories
|
||||
alias ps='ps auxf' # Print all processes
|
||||
alias tty-clock='tty-clock -Ssc' # Terminal clock screensaver
|
||||
|
||||
|
||||
|
||||
# Custom aliases
|
||||
alias reload="exec \$SHELL" # Reload the shell (i.e. invoke as a login shell
|
||||
alias ip-show="dig +short myip.opendns.com @resolver1.opendns.com" # Gets your IP address
|
||||
alias fhere='find . -name' # Find file/dir from currrent dir
|
||||
alias ssh-list='ss | grep ssh' # List all SSH connections
|
||||
alias swapout='sudo swapoff -a; sudo swapon -a' # Reset swap (move everything to RAM)
|
||||
alias cpu-stress='fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd'
|
||||
alias psg='\ps aux | grep -v grep | grep -i -e VSZ -e' # Get searchable process with nice output
|
||||
alias path='echo -e ${PATH//:/\\n}' # Print each PATH entry on a separate line
|
||||
alias colors-256='curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash' # Show color table
|
||||
alias mount-table='df' # Show list of all mounted devices and their mount locations
|
||||
alias create_mirror_list='reflector --country Slovakia --country Czechia --country Poland --country Hungary --country Ukraine --country Germany --country US --latest 800 --protocol https --sort rate --save mirrorlist'
|
||||
alias pacman-extract='pacman -Syw --cachedir .' # Extract package/es into current floders
|
||||
alias clean='rm -rf ~/.local/share/Trash/* && rm -rf ~/Downloads/*' # Remove trash and downloads files
|
||||
|
||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||
alias nvidia='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia' # Run app with nvidia (on hybrid mode with optimus)
|
||||
alias o='dolphin .' # open in dolphin (file manager)
|
||||
alias batinfo='sudo watch -d -n 2 tlp-stat -b'
|
||||
alias sound_control='alsamixer' # Sound control tool in alsa_utils package
|
||||
alias firefox="GTK_USE_PORTAL=1 firefox"
|
||||
alias pdf-reader='mupdf' # Open pdf file
|
||||
alias md-to-pdf='pandoc -s -o' # Convert markdown to pdf
|
||||
alias minecraft='minecraft-launcher'
|
||||
alias metasploit='msfconsole'
|
||||
|
||||
# If user is not root, pass all commands via sudo
|
||||
if [ $UID -ne 0 ]; then
|
||||
# Enable aliases to be sudo’ed
|
||||
|
||||
## Uncomment if you are using autocompletion (is ZSH)
|
||||
#alias sudo='nocorrect sudo'
|
||||
## Comment this if you are not using autocompletion (in ZSH)
|
||||
alias sudo='sudo '
|
||||
|
||||
alias unsudo='sudo -k' # Reset sudo timeout (sudo will require password)
|
||||
fi
|
||||
|
||||
# Normalize `open` across Linux, macOS, and Windows.
|
||||
# This is needed to make `open` function (see below) cross-platform
|
||||
if [ ! $(uname -s) = 'Darwin' ]; then
|
||||
if grep -q Microsoft /proc/version; then
|
||||
# Ubuntu on Windows using the Linux subsystem
|
||||
alias open='explorer.exe'
|
||||
else
|
||||
alias open='xdg-open'
|
||||
fi
|
||||
fi
|
||||
|
||||
# Functions
|
||||
if [ -f ~/.config/sh/functions ]; then
|
||||
source ~/.config/sh/functions
|
||||
fi
|
||||
|
||||
# Extra
|
||||
if [ -f ~/.config/sh/extra ]; then
|
||||
source ~/.config/sh/extra
|
||||
fi
|
169
home/.config/sh/functions
Executable file
169
home/.config/sh/functions
Executable file
|
@ -0,0 +1,169 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function extract {
|
||||
if [ -z "$1" ]; then
|
||||
# display usage if no parameters given
|
||||
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
|
||||
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
|
||||
return 1
|
||||
else
|
||||
for n in $@
|
||||
do
|
||||
if [ -f "$n" ] ; then
|
||||
case "${n%,}" in
|
||||
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
|
||||
tar xvf "$n" ;;
|
||||
*.lzma) unlzma ./"$n" ;;
|
||||
*.bz2) bunzip2 ./"$n" ;;
|
||||
*.rar) unrar x -ad ./"$n" ;;
|
||||
*.gz) gunzip ./"$n" ;;
|
||||
*.zip) unzip ./"$n" ;;
|
||||
*.z) uncompress ./"$n" ;;
|
||||
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
|
||||
7z x ./"$n" ;;
|
||||
*.xz) unxz ./"$n" ;;
|
||||
*.exe) cabextract ./"$n" ;;
|
||||
*)
|
||||
echo "extract: '$n' - unknown archive method"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "'$n' - file does not exist"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Create a new directory and enter it
|
||||
function mkd() {
|
||||
mkdir -p "$@" && cd "$_";
|
||||
}
|
||||
|
||||
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
|
||||
function targz() {
|
||||
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`
|
||||
);
|
||||
|
||||
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}";
|
||||
|
||||
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.";
|
||||
}
|
||||
|
||||
# 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;
|
||||
}
|
||||
|
||||
# Use Git’s colored diff when available
|
||||
hash git &>/dev/null;
|
||||
if [ $? -eq 0 ]; then
|
||||
function diff() {
|
||||
git diff --no-index --color-words "$@";
|
||||
}
|
||||
fi;
|
||||
|
||||
# Create a data URL from a file
|
||||
function dataurl() {
|
||||
local mimeType=$(file -b --mime-type "$1");
|
||||
if [[ $mimeType == text/* ]]; then
|
||||
mimeType="${mimeType};charset=utf-8";
|
||||
fi
|
||||
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
|
||||
}
|
||||
|
||||
# Compare original and gzipped file size
|
||||
function gz() {
|
||||
local origsize=$(wc -c < "$1");
|
||||
local gzipsize=$(gzip -c "$1" | wc -c);
|
||||
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
|
||||
printf "orig: %d bytes\n" "$origsize";
|
||||
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
|
||||
}
|
||||
|
||||
# Show all the names (CNs and SANs) listed in the SSL certificate
|
||||
# for a given domain
|
||||
function getcertnames() {
|
||||
if [ -z "${1}" ]; then
|
||||
echo "ERROR: No domain specified.";
|
||||
return 1;
|
||||
fi;
|
||||
|
||||
local domain="${1}";
|
||||
echo "Testing ${domain}…";
|
||||
echo ""; # newline
|
||||
|
||||
local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \
|
||||
| openssl s_client -connect "${domain}:443" -servername "${domain}" 2>&1);
|
||||
|
||||
if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
|
||||
local certText=$(echo "${tmp}" \
|
||||
| openssl x509 -text -certopt "no_aux, no_header, no_issuer, no_pubkey, \
|
||||
no_serial, no_sigdump, no_signame, no_validity, no_version");
|
||||
echo "Common Name:";
|
||||
echo ""; # newline
|
||||
echo "${certText}" | grep "Subject:" | sed -e "s/^.*CN=//" | sed -e "s/\/emailAddress=.*//";
|
||||
echo ""; # newline
|
||||
echo "Subject Alternative Name(s):";
|
||||
echo ""; # newline
|
||||
echo "${certText}" | grep -A 1 "Subject Alternative Name:" \
|
||||
| sed -e "2s/DNS://g" -e "s/ //g" | tr "," "\n" | tail -n +2;
|
||||
return 0;
|
||||
else
|
||||
echo "ERROR: Certificate not found.";
|
||||
return 1;
|
||||
fi;
|
||||
}
|
||||
|
||||
# `o` with no arguments opens the current directory, otherwise opens the given
|
||||
# location
|
||||
function o() {
|
||||
if [ $# -eq 0 ]; then
|
||||
open .;
|
||||
else
|
||||
open "$@";
|
||||
fi;
|
||||
}
|
||||
|
||||
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
|
||||
# the `.git` directory, listing directories first. The output gets piped into
|
||||
# `less` with options to preserve color and line numbers, unless the output is
|
||||
# small enough for one screen.
|
||||
function tre() {
|
||||
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue