added some zsh plugins

This commit is contained in:
JMARyA 2020-11-09 08:05:39 +01:00
parent 0ef3bd7a55
commit 3a44873f3a
No known key found for this signature in database
GPG key ID: 19BD48AEE60FA00B
14 changed files with 209 additions and 14 deletions

View file

@ -7,4 +7,4 @@ This is a Collection of little ZSHRC Snippets that can be modularly merged into
Specify the features you want in the cat command
## Example
'''cat base mkcd update > ~/.zshrc'''
'''cat base.zsh mkcd.zsh update.zsh > ~/.zshrc'''

View file

@ -43,5 +43,3 @@ export EDITOR="nano"
export PATH=~/bin:$PATH
alias zshconfig="nano ~/.zshrc"
alias zshrefresh="source ~/.zshrc"
alias ls="ls --color=always"
alias la="ls -lah --color=always"

4
cp.plugin.zsh Normal file
View file

@ -0,0 +1,4 @@
cpv() {
rsync -pogbr -hhh --backup-dir=/tmp/rsync -e /dev/null --progress "$@"
}
compdef _files cpv

17
encode64.plugin.zsh Normal file
View file

@ -0,0 +1,17 @@
encode64() {
if [[ $# -eq 0 ]]; then
cat | base64
else
printf '%s' $1 | base64
fi
}
decode64() {
if [[ $# -eq 0 ]]; then
cat | base64 --decode
else
printf '%s' $1 | base64 --decode
fi
}
alias e64=encode64
alias d64=decode64

3
exa.zsh Normal file
View file

@ -0,0 +1,3 @@
alias ls="exa"
alias l="exa -l"
alias la="exa -la"

82
extract.plugin.zsh Normal file
View file

@ -0,0 +1,82 @@
alias x=extract
extract() {
local remove_archive
local success
local extract_dir
if (( $# == 0 )); then
cat <<-'EOF' >&2
Usage: extract [-option] [file ...]
Options:
-r, --remove Remove archive after unpacking.
EOF
fi
remove_archive=1
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
remove_archive=0
shift
fi
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
echo "extract: '$1' is not a valid file" >&2
shift
continue
fi
success=0
extract_dir="${1:t:r}"
case "${1:l}" in
(*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
(*.tar.xz|*.txz)
tar --xz --help &> /dev/null \
&& tar --xz -xvf "$1" \
|| xzcat "$1" | tar xvf - ;;
(*.tar.zma|*.tlz)
tar --lzma --help &> /dev/null \
&& tar --lzma -xvf "$1" \
|| lzcat "$1" | tar xvf - ;;
(*.tar.zst|*.tzst)
tar --zstd --help &> /dev/null \
&& tar --zstd -xvf "$1" \
|| zstdcat "$1" | tar xvf - ;;
(*.tar) tar xvf "$1" ;;
(*.tar.lz) (( $+commands[lzip] )) && tar xvf "$1" ;;
(*.tar.lz4) lz4 -c -d "$1" | tar xvf - ;;
(*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$1" ;;
(*.gz) (( $+commands[pigz] )) && pigz -dk "$1" || gunzip -k "$1" ;;
(*.bz2) bunzip2 "$1" ;;
(*.xz) unxz "$1" ;;
(*.lrz) (( $+commands[lrunzip] )) && lrunzip "$1" ;;
(*.lz4) lz4 -d "$1" ;;
(*.lzma) unlzma "$1" ;;
(*.z) uncompress "$1" ;;
(*.zip|*.war|*.jar|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d $extract_dir ;;
(*.rar) unrar x -ad "$1" ;;
(*.rpm) mkdir "$extract_dir" && cd "$extract_dir" && rpm2cpio "../$1" | cpio --quiet -id && cd .. ;;
(*.7z) 7za x "$1" ;;
(*.deb)
mkdir -p "$extract_dir/control"
mkdir -p "$extract_dir/data"
cd "$extract_dir"; ar vx "../${1}" > /dev/null
cd control; tar xzvf ../control.tar.gz
cd ../data; extract ../data.tar.*
cd ..; rm *.tar.* debian-binary
cd ..
;;
(*.zst) unzstd "$1" ;;
(*)
echo "extract: '$1' cannot be extracted" >&2
success=1
;;
esac
(( success = $success > 0 ? $success : $? ))
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
shift
done
}

View file

View file

@ -1,6 +1,3 @@
function mkcd() {
mkdir $1 && cd $1
}

3
rsync
View file

@ -1,3 +0,0 @@
function rsync_cp() {
rsync -avzhruP $1 $2
}

4
rsync.plugin.zsh Normal file
View file

@ -0,0 +1,4 @@
alias rsync-copy="rsync -avz --progress -h"
alias rsync-move="rsync -avz --progress -h --remove-source-files"
alias rsync-update="rsync -avzu --progress -h"
alias rsync-synchronize="rsync -avzu --delete --progress -h"

90
systemd.plugin.zsh Normal file
View file

@ -0,0 +1,90 @@
user_commands=(
cat
get-default
help
is-active
is-enabled
is-failed
is-system-running
list-dependencies
list-jobs
list-sockets
list-timers
list-unit-files
list-units
show
show-environment
status)
sudo_commands=(
add-requires
add-wants
cancel
daemon-reexec
daemon-reload
default
disable
edit
emergency
enable
halt
hibernate
hybrid-sleep
import-environment
isolate
kexec
kill
link
list-machines
load
mask
poweroff
preset
preset-all
reboot
reenable
reload
reload-or-restart
reset-failed
rescue
restart
revert
set-default
set-environment
set-property
start
stop
suspend
switch-root
try-reload-or-restart
try-restart
unmask
unset-environment)
for c in $user_commands; do; alias sc-$c="systemctl $c"; done
for c in $sudo_commands; do; alias sc-$c="sudo systemctl $c"; done
for c in $user_commands; do; alias scu-$c="systemctl --user $c"; done
for c in $sudo_commands; do; alias scu-$c="systemctl --user $c"; done
alias sc-enable-now="sc-enable --now"
alias sc-disable-now="sc-disable --now"
alias sc-mask-now="sc-mask --now"
alias scu-enable-now="scu-enable --now"
alias scu-disable-now="scu-disable --now"
alias scu-mask-now="scu-mask --now"
function systemd_prompt_info {
local unit
for unit in $@; do
echo -n "$ZSH_THEME_SYSTEMD_PROMPT_PREFIX"
[[ -n "$ZSH_THEME_SYSTEMD_PROMPT_CAPS" ]] && echo -n "${(U)unit}:" || echo -n "$unit:"
if systemctl is-active $unit &>/dev/null; then
echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE"
else
echo -n "$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE"
fi
echo -n "$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX"
done
}

View file

@ -1,10 +1,13 @@
function update() {
if type "apt-get" &> /dev/null; then
sudo apt-get update;
sudo apt-get upgrade;
sudo apt-get dist-upgrade;
fi
if type "apk" &> /dev/null; then
sudo apk update;
sudo apk upgrade;
fi
if type "pacman" &> /dev/null; then
sudo pacman -Syu;
fi