From 3a44873f3a5185c30eb4375b1a66689e2dc63344 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 9 Nov 2020 08:05:39 +0100 Subject: [PATCH] added some zsh plugins --- README.md | 2 +- base => base.zsh | 4 +- cp.plugin.zsh | 4 ++ dot_files => dot_files.zsh | 0 encode64.plugin.zsh | 17 ++++++ exa.zsh | 3 ++ extract.plugin.zsh | 82 +++++++++++++++++++++++++++++ media => media.zsh | 0 mkcd => mkcd.zsh | 3 -- rsync | 3 -- rsync.plugin.zsh | 4 ++ systemd.plugin.zsh | 90 ++++++++++++++++++++++++++++++++ update => update.zsh | 11 ++-- youtube-dl-cmd => youtube-dl.zsh | 0 14 files changed, 209 insertions(+), 14 deletions(-) rename base => base.zsh (93%) create mode 100644 cp.plugin.zsh rename dot_files => dot_files.zsh (100%) create mode 100644 encode64.plugin.zsh create mode 100644 exa.zsh create mode 100644 extract.plugin.zsh rename media => media.zsh (100%) rename mkcd => mkcd.zsh (93%) delete mode 100644 rsync create mode 100644 rsync.plugin.zsh create mode 100644 systemd.plugin.zsh rename update => update.zsh (76%) rename youtube-dl-cmd => youtube-dl.zsh (100%) diff --git a/README.md b/README.md index 03d552b..d2b2866 100644 --- a/README.md +++ b/README.md @@ -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''' diff --git a/base b/base.zsh similarity index 93% rename from base rename to base.zsh index 2c9b2c2..64e22fe 100644 --- a/base +++ b/base.zsh @@ -42,6 +42,4 @@ zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' 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" +alias zshrefresh="source ~/.zshrc" \ No newline at end of file diff --git a/cp.plugin.zsh b/cp.plugin.zsh new file mode 100644 index 0000000..fe6ea87 --- /dev/null +++ b/cp.plugin.zsh @@ -0,0 +1,4 @@ +cpv() { + rsync -pogbr -hhh --backup-dir=/tmp/rsync -e /dev/null --progress "$@" +} +compdef _files cpv diff --git a/dot_files b/dot_files.zsh similarity index 100% rename from dot_files rename to dot_files.zsh diff --git a/encode64.plugin.zsh b/encode64.plugin.zsh new file mode 100644 index 0000000..979e067 --- /dev/null +++ b/encode64.plugin.zsh @@ -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 diff --git a/exa.zsh b/exa.zsh new file mode 100644 index 0000000..7038d47 --- /dev/null +++ b/exa.zsh @@ -0,0 +1,3 @@ +alias ls="exa" +alias l="exa -l" +alias la="exa -la" \ No newline at end of file diff --git a/extract.plugin.zsh b/extract.plugin.zsh new file mode 100644 index 0000000..46e69f0 --- /dev/null +++ b/extract.plugin.zsh @@ -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 +} diff --git a/media b/media.zsh similarity index 100% rename from media rename to media.zsh diff --git a/mkcd b/mkcd.zsh similarity index 93% rename from mkcd rename to mkcd.zsh index 86aac6c..57ac072 100644 --- a/mkcd +++ b/mkcd.zsh @@ -1,6 +1,3 @@ - function mkcd() { mkdir $1 && cd $1 } - - diff --git a/rsync b/rsync deleted file mode 100644 index 7ae793a..0000000 --- a/rsync +++ /dev/null @@ -1,3 +0,0 @@ -function rsync_cp() { - rsync -avzhruP $1 $2 -} diff --git a/rsync.plugin.zsh b/rsync.plugin.zsh new file mode 100644 index 0000000..1a3bb4c --- /dev/null +++ b/rsync.plugin.zsh @@ -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" diff --git a/systemd.plugin.zsh b/systemd.plugin.zsh new file mode 100644 index 0000000..c6fd529 --- /dev/null +++ b/systemd.plugin.zsh @@ -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 +} + diff --git a/update b/update.zsh similarity index 76% rename from update rename to update.zsh index e7b1ccb..25e0c96 100644 --- a/update +++ b/update.zsh @@ -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 @@ -18,9 +21,9 @@ function update() { flatpak update; fi if type "brew" &> /dev/null; then - brew update; - brew upgrade; - brew cask upgrade; + brew update; + brew upgrade; + brew cask upgrade; fi } diff --git a/youtube-dl-cmd b/youtube-dl.zsh similarity index 100% rename from youtube-dl-cmd rename to youtube-dl.zsh