config/shell: Separate config for debian-based distros and fix errors

This commit is contained in:
xerus2000 2020-10-08 11:11:51 +02:00
parent 03bbddea87
commit 04c64fbbe0
3 changed files with 243 additions and 239 deletions

89
.config/shell/debian Normal file
View File

@ -0,0 +1,89 @@
which apt >/dev/null || return
addalternative() {
sudo update-alternatives --install /usr/bin/$1 $1 "$(which "$1$2")" 1
}
snapinstall() {
sudo snap install "$@" && refreshSetup
}
alias aptupdate='sudo apt-get update'
alias aptremove='sudo apt-get remove'
alias aptpurge='sudo apt-get purge'
alias aptclean='sudo apt-get clean && sudo apt-get autoremove'
upgrade() {
if test -x /usr/bin/pkcon
then sudo pkcon update
else sudo apt update && sudo apt upgrade
fi
sudo snap refresh
flatpak update -y
sudo npm update -g
# npm -g outdated --parseable=true | cut -d : -f 4 | xargs -n 1 npm -g install
}
uma() {
if test "$1"
then printf 'y\nj\na' | umake "$1" "$2" "/opt/${3:-$2}"
else
uma ide idea-ultimate idea
uma android android-studio android/android-studio && yes | /opt/android/sdk/tools/bin/sdkmanager --licenses && pathadd /opt/android/sdk/tools/bin /opt/android/sdk/platform-tools && sudo apt install qemu-kvm && sudo adduser janek kvm
test -d "/opt/vscode" && uma ide visual-studio-code vscode
fi
}
alias aptrepo='sudo add-apt-repository'
_aptrepo_n="$(test "$OSTYPE" != "cygwin" && add-apt-repository --help | grep -- "-n")"
aptrepon() {
test $_aptrepo_n && aptrepo -y -n "$@" || aptrepo -y "$@"
}
aptrepos() {
for repo in "$@"
do aptrepon $repo
done
aptupdate
}
alias aptinstall='sudo apt-get install'
aptinstalls() {
apt-cache show "$1" | grep --color=never '\(Version\|Description\):'
aptinstall "$@"
}
aptinstalli() {
apt download $1
sudo dpkg --ignore-depends=$2 -i $1*.deb
}
aptrepoinstall() {
aptrepo -yu $1
if (( $# > 1 ))
then aptinstall "${@:2}"
else aptinstall "${1##*/}"
fi
}
# Gets the download url for the latest release of a package provided via GitHub Releases
# Usage: ghrelease USER REPO [PATTERN]
ghrelease() {
result=$(curl -s "https://api.github.com/repos/$1/$2/releases/latest" | grep -o "http.*${3:-deb}" | awk '{ print length(), $0}' | sort -n | cut -d' ' -f2-)
echo "$result" | grep amd64 || echo "$result"
}
# Installs a local or remote(http/https) deb package and removes it after installation
installdeb() {
loc="/tmp/install.deb"
case $1 in
http*) wget -O "$loc" $1;;
*) loc="$1";;
esac
sudo dpkg -i "$loc" "${@:2}" && sudo apt -f install && rm "$loc"
}
installgh() {
installdeb $(ghrelease "$@")
}
# Downloads all dependencies of a package into the current directory
download-debs() {
apt-get download $1 && apt-cache depends -i $1 | awk '/Depends:/ {print $2}' | xargs apt-get download
}

View File

@ -3,7 +3,7 @@
ulimit -c unlimited # Enable core dumps ulimit -c unlimited # Enable core dumps
export LESS=-R export LESS=-R
export DIST=$(lsb_release --id | cut -d' ' -f2) which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2)
alias info='info --vi-keys' alias info='info --vi-keys'
# Some aliases # Some aliases
@ -41,7 +41,7 @@ edshell() {
} }
edbin() { edbin() {
file="$( (command which $1 || find $HOME/.local/bin -name "$1*" | grep . -m 1 || echo "$HOME/.local/bin/$1") | tail -1 )" file="$( (which $1 || find $HOME/.local/bin -name "$1*" | grep . -m 1 || echo "$HOME/.local/bin/$1") | tail -1 )"
editright "$file" editright "$file"
case "$file" in $HOME) yadm add "$file";; esac case "$file" in $HOME) yadm add "$file";; esac
} }
@ -68,8 +68,8 @@ alias twtest='( TIMEWARRIORDB=/tmp/timewarriordb && rm -rf ${TIMEWARRIORDB} && m
# Quick shortcuts # Quick shortcuts
alias c='clear' alias c='clear'
alias q='exit'
alias v='nvim' alias v='nvim'
alias sudo='sudo -v; sudo '
alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G' alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
alias lar='last | tac' alias lar='last | tac'
@ -108,7 +108,7 @@ alias vrecd="ls $XDG_DATA_HOME/nvim/swap | head -1 | xargs -r rm"
alias dict="(builtin cd $(dirname $(locate -n 2 /dict.txt)) && rlwrap perl dictcc-helper.pl)" alias dict="(builtin cd $(dirname $(locate -n 2 /dict.txt)) && rlwrap perl dictcc-helper.pl)"
alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G' alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G'
dropbox_path="$(cat ~/.dropbox/info.json | grep -Po '"'"path"'"\s*:\s*"\K([^"]*)')" test -d $HOME/.dropbox && dropbox_path="$(cat $HOME/.dropbox/info.json | grep -Po '"'"path"'"\s*:\s*"\K([^"]*)')"
# Add an "alert" alias for long running commands. Use like so: sleep 10; alert # Add an "alert" alias for long running commands. Use like so: sleep 10; alert
#if [ command -v notify-send >/dev/null 2>&1 ]; then #if [ command -v notify-send >/dev/null 2>&1 ]; then
@ -325,95 +325,6 @@ resetdocker() {
#aptinstall docker-ce #aptinstall docker-ce
} }
# INSTALL
addalternative() {
sudo update-alternatives --install /usr/bin/$1 $1 "$(which "$1$2")" 1
}
snapinstall() {
sudo snap install "$@" && refreshSetup
}
alias aptupdate='sudo apt-get update'
alias aptremove='sudo apt-get remove'
alias aptpurge='sudo apt-get purge'
alias aptclean='sudo apt-get clean && sudo apt-get autoremove'
upgrade() {
if test -x /usr/bin/pkcon
then sudo pkcon update
else sudo apt update && sudo apt upgrade
fi
sudo snap refresh
flatpak update -y
sudo npm update -g
# npm -g outdated --parseable=true | cut -d : -f 4 | xargs -n 1 npm -g install
}
uma() {
if test "$1"
then printf 'y\nj\na' | umake "$1" "$2" "/opt/${3:-$2}"
else
uma ide idea-ultimate idea
uma android android-studio android/android-studio && yes | /opt/android/sdk/tools/bin/sdkmanager --licenses && pathadd /opt/android/sdk/tools/bin /opt/android/sdk/platform-tools && sudo apt install qemu-kvm && sudo adduser janek kvm
test -d "/opt/vscode" && uma ide visual-studio-code vscode
fi
}
alias aptrepo='sudo add-apt-repository'
_aptrepo_n="$(test "$OSTYPE" != "cygwin" && add-apt-repository --help | grep -- "-n")"
aptrepon() {
test $_aptrepo_n && aptrepo -y -n "$@" || aptrepo -y "$@"
}
aptrepos() {
for repo in "$@"
do aptrepon $repo
done
aptupdate
}
alias aptinstall='sudo apt-get install'
aptinstalls() {
apt-cache show "$1" | grep --color=never '\(Version\|Description\):'
aptinstall "$@"
}
aptinstalli() {
apt download $1
sudo dpkg --ignore-depends=$2 -i $1*.deb
}
aptrepoinstall() {
aptrepo -yu $1
if (( $# > 1 ))
then aptinstall "${@:2}"
else aptinstall "${1##*/}"
fi
}
# Gets the download url for the latest release of a package provided via GitHub Releases
# Usage: ghrelease USER REPO [PATTERN]
ghrelease() {
result=$(curl -s "https://api.github.com/repos/$1/$2/releases/latest" | grep -o "http.*${3:-deb}" | awk '{ print length(), $0}' | sort -n | cut -d' ' -f2-)
echo "$result" | grep amd64 || echo "$result"
}
# Installs a local or remote(http/https) deb package and removes it after installation
installdeb() {
loc="/tmp/install.deb"
case $1 in
http*) wget -O "$loc" $1;;
*) loc="$1";;
esac
sudo dpkg -i "$loc" "${@:2}" && sudo apt -f install && rm "$loc"
}
installgh() {
installdeb $(ghrelease "$@")
}
# Downloads all dependencies of a package into the current directory
download-debs() {
apt-get download $1 && apt-cache depends -i $1 | awk '/Depends:/ {print $2}' | xargs apt-get download
}
# RANDOM # RANDOM
typeset -A _clean_map typeset -A _clean_map

View File

@ -5,31 +5,35 @@ alias magit='nvim -c MagitOnly'
# if in home or under XDG_CONFIG_HOME 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() {
test "$1" = "config" || case "$PWD" in case "$1" in
$HOME|$XDG_CONFIG_HOME|$LAST_YADM) config) ;;
yadm "$@" clone) ;;
return *) case "$PWD" in
;; $HOME|$XDG_CONFIG_HOME|$LAST_YADM)
$XDG_CONFIG_HOME*) yadm "$@"
if ! command git rev-parse --show-toplevel &>/dev/null; then return
export LAST_YADM="$PWD" ;;
yadm "$@" $XDG_CONFIG_HOME*)
return if ! command git rev-parse --show-toplevel &>/dev/null; then
fi;; export LAST_YADM="$PWD"
esac yadm "$@"
command git "$@"; return
fi;;
esac;;
esac
command git "$@";
} }
# Log local and upstream commits side by side - useful to check before forcing an action # Log local and upstream commits side by side - useful to check before forcing an action
glno() { glno() {
loc="$(git l --color=always "$@")" loc="$(git l --color=always "$@")"
upstream="$(git l --color=always $(git upstream) "$@")" upstream="$(git l --color=always $(git upstream) "$@")"
a=$(echo $loc | wc -l) a=$(echo $loc | wc -l)
b=$(echo $upstream | wc -l) b=$(echo $upstream | wc -l)
halfcols="$(($(tput cols) / 2))" halfcols="$(($(tput cols) / 2))"
for i in `seq 1 $([ $a -le $b ] && echo "$a" || echo "$b")`; do for i in `seq 1 $([ $a -le $b ] && echo "$a" || echo "$b")`; do
printf "%-${halfcols}s %s\n" "$(echo $loc | head -n $i | tail -1)" "$(echo $upstream | head -n $i | tail -1)" printf "%-${halfcols}s %s\n" "$(echo $loc | head -n $i | tail -1)" "$(echo $upstream | head -n $i | tail -1)"
done done
} }
# Shortcuts # Shortcuts
@ -40,28 +44,28 @@ gitchild() { git log --reverse --ancestry-path --pretty=%H $1..${2:-HEAD} | head
# Caching # Caching
gitrecache() { gitrecache() {
git rm --cached --quiet -r ${1:-.} git rm --cached --quiet -r ${1:-.}
git add ${1:-.} git add ${1:-.}
git status -s git status -s
} }
gitrestore() { gitrestore() {
git reset -- "$@" git reset -- "$@"
git checkout -- "$@" git checkout -- "$@"
} }
# Branches # Branches
alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done' alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done'
gitrebranch() { gitrebranch() {
branch=${1:-$(git curbranch)} branch=${1:-$(git curbranch)}
test "$(git curbranch)" = "$branch" && git checkout ${2:-master} test "$(git curbranch)" = "$branch" && git checkout ${2:-master}
git branch -D $branch git branch -D $branch
git checkout -b $branch git checkout -b $branch
} }
gitrmbranch() { gitrmbranch() {
branch=${1:-$(git curbranch)} branch=${1:-$(git curbranch)}
git push -d $(git rev-parse --abbrev-ref $branch@{u} | sed 's/\// /' || echo origin $branch) git push -d $(git rev-parse --abbrev-ref $branch@{u} | sed 's/\// /' || echo origin $branch)
test $1 || git checkout master || git checkout $(cat .git/refs/remotes/origin/HEAD | cut -d'/' -f4) test $1 || git checkout master || git checkout $(cat .git/refs/remotes/origin/HEAD | cut -d'/' -f4)
git branch -D $branch git branch -D $branch
} }
# Save HEAD commit hash to "snap" file in git dir # Save HEAD commit hash to "snap" file in git dir
@ -71,84 +75,84 @@ gitsnaprestore() { git reset --hard $(cat "$(git dir)/${1:-snap}") }
# Remove list of tags local & remote # Remove list of tags local & remote
gitrmtag() { gitrmtag() {
declare -a refs declare -a refs
local index=1 local index=1
for tag in $@; do refs[index++]=":refs/tags/$tag"; done for tag in $@; do refs[index++]=":refs/tags/$tag"; done
git push origin "${refs[@]}" && git tag -d "$@" git push origin "${refs[@]}" && git tag -d "$@"
} }
# Rename a tag # Rename a tag
gitretag() { gitretag() {
git push origin refs/tags/${1}:refs/tags/${2} :refs/tags/$1 && git tag -d $1 git push origin refs/tags/${1}:refs/tags/${2} :refs/tags/$1 && git tag -d $1
} }
# Repo management {{{ # Repo management {{{
gitinit() { gitinit() {
git init git init
git add . git add .
git commit -m "First strike" git commit -m "First strike"
gitorigin "$@" gitorigin "$@"
git push git push
} }
gitbackup() { gitbackup() {
p=$(basename $PWD) p=$(basename $PWD)
builtin cd .. builtin cd ..
git clone --mirror $p git clone --mirror $p
cd $p cd $p
} }
project() { project() {
cd $projects_dir cd $projects_dir
if [ -d $2 ] if [ -d $2 ]
then cd "$2" && gitorigin "$@" then cd "$2" && gitorigin "$@"
else gitclone "$@" else gitclone "$@"
fi fi
} }
gitremote() { gitremote() {
case "$1" in case "$1" in
http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;; http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;;
git:*) echo "$1" ;; git:*) echo "$1" ;;
*) test "$3" = "cau" && 3="CAU-Kiel-Tech-Inf" *) test "$3" = "cau" && 3="CAU-Kiel-Tech-Inf"
test "$3" = "btl" && 3="betweenthelinesev" test "$3" = "btl" && 3="betweenthelinesev"
echo "git@git${1:-hub}.com:${3:-xerus2000}/${2:-$(basename $PWD)}.git" ;; echo "git@git${1:-hub}.com:${3:-xerus2000}/${2:-$(basename $PWD)}.git" ;;
esac esac
} }
gitclone() { gitclone() {
remote=$(gitremote "$@") remote=$(gitremote "$@")
echo $remote echo $remote
git clone $remote ${@:4} git clone $remote ${@:4}
cd "$(test $4 && echo $4 || basename ${remote/.git})" cd "$(test $4 && echo $4 || basename ${remote/.git})"
} }
gitfork() { gitfork() {
builtin cd "$projects_dir/_forks" builtin cd "$projects_dir/_forks"
gitclone hub "$1" "" "$3" --recurse-submodules gitclone hub "$1" "" "$3" --recurse-submodules
test "$2" && git remote add upstream "$(gitremote hub "$1" "$2")" test "$2" && git remote add upstream "$(gitremote hub "$1" "$2")"
git remote -v git remote -v
} }
# set repo as origin and set all branches upstream to their respective remote branch, if available # set repo as origin and set all branches upstream to their respective remote branch, if available
gitorigin() { gitorigin() {
git remote remove origin 2>/dev/null git remote remove origin 2>/dev/null
git remote add origin $(gitremote "$@") git remote add origin $(gitremote "$@")
git remote -v && git fetch || ( last=$? && echo "git fetch failed, aborting\!" && return $last ) git remote -v && git fetch || ( last=$? && echo "git fetch failed, aborting\!" && return $last )
git branch | sed 's/ //g' | sed 's/*//' | while read branch git branch | sed 's/ //g' | sed 's/*//' | while read branch
do test $(git branch -a | grep origin/$branch | wc -l) -gt 0 && git branch -u origin/$branch $branch do test $(git branch -a | grep origin/$branch | wc -l) -gt 0 && git branch -u origin/$branch $branch
done done
} }
# set repo as upstream or add a new remote # set repo as upstream or add a new remote
gitupstream() { gitupstream() {
if test "$2" if test "$2"
then local name="$2"; git remote remove "$2" >/dev/null then local name="$2"; git remote remove "$2" >/dev/null
else git remote get-url upstream &>/dev/null && local name="$1" || local name="upstream" else git remote get-url upstream &>/dev/null && local name="$1" || local name="upstream"
fi fi
local origin="$(git remote get-url origin)" 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 add -f $name "$(echo $origin | cut -d':' -f1):$1/$(echo $origin | cut -d'/' -f2)"
git remote -v git remote -v
} }
# }}} # }}}
@ -156,92 +160,92 @@ gitupstream() {
# gets the AuthorDate of a given committish # gets the AuthorDate of a given committish
git-authordate() { git-authordate() {
local date=$(git log --pretty=fuller --date=raw -1 $1 | grep AuthorDate) local date=$(git log --pretty=fuller --date=raw -1 $1 | grep AuthorDate)
echo ${date##*: } echo ${date##*: }
} }
# executes a git command (usually commit) with the date of a given committish # executes a git command (usually commit) with the date of a given committish
git-withdate() { git-withdate() {
date=$(git-authordate $1) date=$(git-authordate $1)
GIT_AUTHOR_DATE="$date" GIT_COMMITTER_DATE="$date" git "${@:2}" GIT_AUTHOR_DATE="$date" GIT_COMMITTER_DATE="$date" git "${@:2}"
} }
# takes all changes in the current working tree and amends them to the given commit # takes all changes in the current working tree and amends them to the given commit
gitedit() { gitedit() {
git stash git stash
gitcommits -q $1 gitcommits -q $1
git reset --hard $1 git reset --hard $1
git stash pop -q git stash pop -q
git-withdate $1 commit --all --amend "${@:2}" git-withdate $1 commit --all --amend "${@:2}"
gitcommits gitcommits
} }
# takes two committishs and squashes them with all commits between them into a single commit # takes two committishs and squashes them with all commits between them into a single commit
# this will rewrite the full history from then on, but should not create any conflicts # this will rewrite the full history from then on, but should not create any conflicts
gitsquash() { gitsquash() {
local -a options local -a options
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
-i) ignore=true; shift 1;; -i) ignore=true; shift 1;;
-f|--force) force=true; shift 1;; -f|--force) force=true; shift 1;;
-*) options+=($1); exit 1;; -*) options+=($1); exit 1;;
*) break;; *) break;;
esac esac
done done
((#!=2)) && echo "Usage: [options] <startcommit> <endcommit>" && return 1 ((#!=2)) && echo "Usage: [options] <startcommit> <endcommit>" && return 1
[[ -n $(git status -s) ]] && [ ! $force ] && echo -e "Tree is dirty, commit or stash your changes first!\nIf you want to execute the command regardless, run again with --force" && return 1 [[ -n $(git status -s) ]] && [ ! $force ] && echo -e "Tree is dirty, commit or stash your changes first!\nIf you want to execute the command regardless, run again with --force" && return 1
1=$(git rev-parse $1) 1=$(git rev-parse $1)
2=$(git rev-parse $2) 2=$(git rev-parse $2)
[ $(git rev-list $1 --count) -lt $(git rev-list $2 --count) ] && t=$1 && 1=$2 && 2=$t [ $(git rev-list $1 --count) -lt $(git rev-list $2 --count) ] && t=$1 && 1=$2 && 2=$t
gitcommits -q $1 gitcommits -q $1
git reset --hard $1 git reset --hard $1
if [ $(git rev-list $2 --count) = 1 ]; then if [ $(git rev-list $2 --count) = 1 ]; then
git update-ref -d HEAD git update-ref -d HEAD
git add . git add .
git-withdate $1 commit -c $1 git-withdate $1 commit -c $1
else else
git reset -q $2 git reset -q $2
git add . git add .
git commit --amend git commit --amend
fi fi
gitcommits gitcommits
} }
# given a committish, this command saves a list of commits between the HEAD and the given committish into the .git directory # given a committish, this command saves a list of commits between the HEAD and the given committish into the .git directory
# when ran without parameters it applies the saved list of commits onto the current HEAD # when ran without parameters it applies the saved list of commits onto the current HEAD
gitcommits() { gitcommits() {
verbosity=1 verbosity=1
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
-v) verbosity=2; shift 1;; -v) verbosity=2; shift 1;;
-q|--quiet) verbosity=0; shift 1;; -q|--quiet) verbosity=0; shift 1;;
--theirs) params=(-X theirs); shift 1;; --theirs) params=(-X theirs); shift 1;;
*) break;; *) break;;
esac esac
done done
stashed="$(git rev-parse --show-toplevel)/.git/stashed-commits" stashed="$(git rev-parse --show-toplevel)/.git/stashed-commits"
if [ $1 ]; then if [ $1 ]; then
if [ $verbosity -eq 0 ] if [ $verbosity -eq 0 ]
then git rev-list --reverse HEAD...$1 >$stashed then git rev-list --reverse HEAD...$1 >$stashed
else git rev-list --reverse HEAD...$1 | tee $stashed else git rev-list --reverse HEAD...$1 | tee $stashed
fi fi
else else
local aborted local aborted
for commit in $(cat $stashed); do for commit in $(cat $stashed); do
[ $aborted ] && rest+=($commit) && continue [ $aborted ] && rest+=($commit) && continue
[ $verbosity -gt 0 ] && git --no-pager log --oneline -1 $commit [ $verbosity -gt 0 ] && git --no-pager log --oneline -1 $commit
git-withdate $commit cherry-pick $commit ${params:0} >/dev/null git-withdate $commit cherry-pick $commit ${params:0} >/dev/null
last=$? last=$?
[ $last -gt 0 ] && aborted=true && typeset -a rest && continue [ $last -gt 0 ] && aborted=true && typeset -a rest && continue
[ $verbosity -gt 0 ] && echo -e "\e[1A$(git log --color=always --pretty=format:"%C(yellow)$(git rev-parse --short HEAD^^)%C(bold) -> %Creset%C(yellow)%h%Creset %s" -1)" [ $verbosity -gt 0 ] && echo -e "\e[1A$(git log --color=always --pretty=format:"%C(yellow)$(git rev-parse --short HEAD^^)%C(bold) -> %Creset%C(yellow)%h%Creset %s" -1)"
[ $verbosity -gt 1 ] && git status -s [ $verbosity -gt 1 ] && git status -s
done done
echo $rest >$stashed echo $rest >$stashed
[ $aborted ] && echo "A problem was encountered. Fix it and run 'gitcommits' again to apply the remaining ${#rest} commits." [ $aborted ] && echo "A problem was encountered. Fix it and run 'gitcommits' again to apply the remaining ${#rest} commits."
fi fi
} }
# }}} # }}}