.config/shell: Improve some aliases

This commit is contained in:
xerus2000 2020-06-26 23:25:53 +02:00
parent 63079544d0
commit 42ae473420
2 changed files with 59 additions and 27 deletions

View File

@ -1,14 +1,23 @@
# Shell configuration for Zsh, works almost completely for Bash as well # Shell configuration for Zsh, works almost completely for Bash as well
export LESS=-R export LESS=-R
alias info='info --vi-keys'
export DIST=$(lsb_release --id | cut -d' ' -f2) export DIST=$(lsb_release --id | cut -d' ' -f2)
alias info='info --vi-keys'
# Some aliases # Some aliases
alias conf='{ fd -t f . --full-path $(xdg-user-dir CONFIG) /etc; echo ~/.gradle/gradle.properties } | fzf --tiebreak=end,length --preview "bat --color=always --style=numbers --line-range :500 {}" --bind "enter:execute(test -O {} && $EDITOR {} || sudoedit {}),del:execute(gio trash {}),change:top"'
alias editgrub='sudoedit /etc/default/grub && sudo update-grub' alias editgrub='sudoedit /etc/default/grub && sudo update-grub'
alias editenv='sudoedit /etc/environment' alias editenv='sudoedit /etc/environment'
conf() {
conf_cache="$XDG_CACHE_HOME/conf"
conf_tmp="${conf_cache}.tmp"
conf_extra="$XDG_CONFIG_HOME/conf-extra"
touch "$conf_cache"
# | xargs file | grep text | cut -d':' -f1 # this filters out non-text files, but it's ridiculously slow
sel="$({ cat $conf_cache $conf_extra; fd --type file --size -1m --hidden --exact-depth 1 . ~; fd --type file --size -1m --max-depth 3 . --full-path $XDG_CONFIG_HOME /etc } | awk '!a[$0]++' | fzf -1 -0 --tiebreak=end,length --preview 'bat --color=always --style=numbers --line-range :200 {}')"
test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -9 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & (test -O "$sel" && $EDITOR "$sel" || sudoedit "$sel"))
}
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}" CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
alias r="reset && exec zsh" alias r="reset && exec zsh"
editshell() { editshell() {
@ -31,9 +40,17 @@ alias tw='timew'
alias c='clear' alias c='clear'
alias q='exit' alias q='exit'
alias v='nvim' alias v='nvim'
alias lar='last | tac'
alias grp='grep -iIn' alias grp='grep -iIn'
alias grpr='grp -r' alias grpr='grp -r'
b() { bat "$@" 2>/dev/null || ls -lah "$@" } b() {
arg=$(test $# -gt 0 && echo "${@: -1}" || echo .)
file $arg | grep -v --color=never directory
case "$(file --dereference $arg)" in
*directory) ls -lAHh "$@";;
*text*) bat --style=numbers "$@";;
esac
}
cdd() { cd "$@" 2>/dev/null || cd "$(dirname "$1")" "${@:2}" } cdd() { cd "$@" 2>/dev/null || cd "$(dirname "$1")" "${@:2}" }
tr() { tree -C -a -L 2 "$@" | less } tr() { tree -C -a -L 2 "$@" | less }
alias sc='sudo systemctl' alias sc='sudo systemctl'
@ -69,11 +86,13 @@ mozedit() (
cat "$tmpfile2" | sed "$2" | lz4 -l | dd bs=1 skip=8 seek=12 of="$file" conv=notrunc cat "$tmpfile2" | sed "$2" | lz4 -l | dd bs=1 skip=8 seek=12 of="$file" conv=notrunc
) )
theme_save="$(xdg-user-dir CACHE)/theme" theme_save="/tmp/theme"
theme_default="dark" theme_default="$(d=$(date +%H) && test $d -lt 7 && test $d -gt 17 && echo dark || echo light)"
theme() { theme() {
theme="$1" theme="$1"
if test "$2" = "kde" || test "$theme" != "$THEME" -a "$2" != "q" if test "$2" = "kde"
then kcmshell5 kcm_lookandfeel
elif test "$theme" != "$THEME" -a "$2" != "q"
then kcmshell5 kcm_lookandfeel & then kcmshell5 kcm_lookandfeel &
fi fi
export THEME="$theme" export THEME="$theme"
@ -83,14 +102,14 @@ theme() {
case "$theme" in case "$theme" in
(light) (light)
export BAT_THEME="OneHalfLight" export BAT_THEME="OneHalfLight"
konsoleprofile colors="Light" konsoleprofile colors="Light"
sed -i 's/#\(include.*\/light-256.theme\)/\1/' "$(xdg-user-dir CONFIG)/taskrc" sed -i 's/#\(include.*\/light-256.theme\)/\1/' "$XDG_CONFIG_HOME/taskrc"
#mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/' #mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/'
;; ;;
(dark) (dark)
export BAT_THEME="OneHalfDark" export BAT_THEME="OneHalfDark"
konsoleprofile colors="Breeze" konsoleprofile colors="Breeze"
sed -i 's/^include.*light-256.theme/#\0/' "$(xdg-user-dir CONFIG)/taskrc" sed -i 's/^include.*light-256.theme/#\0/' "$XDG_CONFIG_HOME/taskrc"
#mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/' #mozedit $mozfile '/light@mozilla/,/"enabled"/ s/\("enabled":.*\)true/\1false/; /dark@mozilla/,/"enabled"/ s/\("enabled":.*\)false/\1true/'
;; ;;
esac esac
@ -275,6 +294,10 @@ aptrepos() {
aptupdate aptupdate
} }
alias aptinstall='sudo apt-get install' alias aptinstall='sudo apt-get install'
aptinstalls() {
apt-cache show "$1" | grep --color=never '\(Version\|Description\):'
aptinstall "$@"
}
aptrepoinstall() { aptrepoinstall() {
aptrepo -yu $1 aptrepo -yu $1
if (( $# > 1 )) if (( $# > 1 ))
@ -316,12 +339,11 @@ download-debs() {
typeset -A _clean_map typeset -A _clean_map
if test "$BASH_VERSION" if test "$BASH_VERSION"
then _clean_map=([m]=~/.mozilla [c]=~/.cache) then _clean_map=([c]=$XDG_CACHE_HOME [t]=/var/tmp)
else _clean_map=(m ~/.mozilla c ~/.cache) else _clean_map=(c $XDG_CACHE_HOME t /var/tmp)
fi fi
_clean_folders=(~/.oracle_jre_usage ~/.gradle-kotlin-dsl ~/.thumbnails) _clean_folders=()
clean() { clean() {
for f in $_clean_folders for f in $_clean_folders
do test -d $f && rm -rv $f do test -d $f && rm -rv $f
done done
@ -329,7 +351,7 @@ clean() {
highlight "g to clean gradle" highlight "g to clean gradle"
if [[ $1 =~ "g" ]]; then if [[ $1 =~ "g" ]]; then
find ~/.gradle/* -maxdepth 0 -not -name "gradle.properties" -exec rm -r {} \; -print find ~/.gradle/* -maxdepth 0 -not -name "gradle.properties" -exec rm -r {} \; -print
find ~/daten/projects/ -name .gradle -print -exec rm -r {} \; find $projects_dir -name .gradle -print -exec rm -r {} \;
fi fi
if test "$BASH_VERSION"; then if test "$BASH_VERSION"; then

View File

@ -2,11 +2,16 @@
alias bfg='java -jar ~/daten/dropbox/tools/bfg-1.13.0.jar' alias bfg='java -jar ~/daten/dropbox/tools/bfg-1.13.0.jar'
alias magit='nvim -c MagitOnly' alias magit='nvim -c MagitOnly'
# if in home or xdg-config and not within a git directory, replace git by yadm # if in home or under XDG_CONFIG_HOME and not within a git directory, replace git by yadm
git() { git() {
case "$PWD" in test "$1" = "config" || case "$PWD" in
~|$(xdg-user-dir CONFIG)*) $HOME|$XDG_CONFIG_HOME|$LAST_YADM)
if ! command git rev-parse --show-toplevel 2&>/dev/null; then yadm "$@"
return
;;
$XDG_CONFIG_HOME*)
if ! command git rev-parse --show-toplevel &>/dev/null; then
export LAST_YADM="$PWD"
yadm "$@" yadm "$@"
return return
fi;; fi;;
@ -40,7 +45,9 @@ glno() {
alias gfs='git fetch && git status -s -b' alias gfs='git fetch && git status -s -b'
alias glu='git pull upstream $(git curbranch)' alias glu='git pull upstream $(git curbranch)'
alias gluu='git pull upstream $(git curbranch) && git push --no-verify' alias gluu='git pull upstream $(git curbranch) && git push --no-verify'
alias gcap!='git commit -a --amend --no-edit && git push --force-with-lease' alias gcap!='git commit --all --amend --no-edit && git push --force-with-lease'
alias gpf='gt push --force-with-lease'
alias grh='git reset HEAD~'
alias grh!='git reset --hard' alias grh!='git reset --hard'
alias grhr='git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})' alias grhr='git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})'
alias gitgc='git gc && git repack -a -d' alias gitgc='git gc && git repack -a -d'
@ -73,7 +80,7 @@ gitrebranch() {
gitrmbranch() { gitrmbranch() {
branch=${1:-$(git curbranch)} branch=${1:-$(git curbranch)}
git push -d origin $branch git push -d origin $branch
test $1 || git checkout master test $1 || git checkout master || git checkout $(cat .git/refs/remotes/origin/HEAD | cut -d'/' -f4)
git branch -D $branch git branch -D $branch
} }
@ -132,7 +139,7 @@ gitclone() {
remote=$(gitremote "$@") remote=$(gitremote "$@")
echo $remote echo $remote
git clone $remote "${@:4}" git clone $remote "${@:4}"
cd "$(basename ${remote/.git})" cd "$(test $4 && echo $4 || basename ${remote/.git})"
} }
gitfork() { gitfork() {
@ -153,12 +160,15 @@ gitorigin() {
done done
} }
# set repo as upstream # set repo as upstream or add a new remote
gitupstream() { gitupstream() {
local name="${2:-upstream}" if test "$2"
git remote remove $name 2>/dev/null then local name="$2"; git remote remove "$2" >/dev/null
git remote add $name "$(git remote -v | grep origin | head -1 | cut -f2 | cut -d':' -f1):$1/$(git remote -v | grep origin | head -1 | cut -f2 | cut -d'/' -f2 | cut -d' ' -f1)" else git remote get-url upstream &>/dev/null && local name="$1" || local name="upstream"
git remote -v && git fetch $name || ( last=$? && echo "git fetch failed, aborting!" && return $last ) fi
local origin="$(git remote get-url origin)"
git remote add -f $name "$(echo $origin | cut -d':' -f1):$1/$(echo $origin | cut -d'/' -f2)"
git remote -v
} }
# }}} # }}}