diff --git a/bash/bash_aliases b/bash/bash_aliases index 2ac4704..d70430d 100644 --- a/bash/bash_aliases +++ b/bash/bash_aliases @@ -1,25 +1,3 @@ -# User specific aliases and functions -alias cdpex='cd ~/Documents/Education/UniBas/FS23/pids23/exercises/pids_2023/exercises/' -alias uni23='cd ~/Nextcloud/Documents/Unibas/HS23/' -alias thoc='cd ~/Nextcloud/Documents/Unibas/FS23/thoc/' -alias inetsec='cd ~/Nextcloud/Documents/Unibas/FS23/inetsec/' -#cd into os alias -alias os='cd ~/Nextcloud/Documents/Unibas/FS23/os/' -alias pkvps='cd ~/Nextcloud/Documents/Unibas/FS23/pkvps/' -alias pids='cd ~/Nextcloud/Documents/Unibas/FS23/pids/' -alias pr23='cd ~/Documents/Education/UniBas/HS23/pr23/' -alias db23='cd ~/Documents/Education/UniBas/HS23/databases/' -alias pet23='cd ~/Documents/Education/UniBas/HS23/pethpc23/' -alias diskmath='cd ~/Documents/Education/UniBas/HS23/diskmath-tutorat23/' -alias pullbooks='rsync -av ~/Nextcloud/Books/ ~/Books' -alias pushbooks='rsync -av ~/Books/ ~/Nextcloud/Books' -alias pushfs24='rsync -uav --exclude=".*" --exclude="__*" --exclude="/venv" ~/documents/education/unibas/fs24/ ~/Nextcloud/Documents/Unibas/FS24' -alias pullfs24='rsync -uav --exclude=".*" ~/Nextcloud/Documents/Unibas/FS24/ ~/documents/education/unibas/fs24' -alias fs24l='cd ~/documents/education/unibas/fs24' -alias fs24c='cd ~/Nextcloud/Documents/Unibas/FS24' -alias sdev='ssh sebl@slenzlinger.dev' -alias sslenz='ssh fm18b_sebaschi@slenzlinger.ch' - # # eza aliases # @@ -36,18 +14,48 @@ alias l='eza -CF' alias g='git' alias gs='git status' alias ga='git add' +alias gaa='git add --all' + alias gc='git commit' alias gcm='git commit -m' alias gca='git commit --amend' + alias gco='git checkout' alias gcb='git checkout -b' + alias gcp='git cherry-pick' alias gcl='git clone' -alias gpr='git pull --rebase' + +alias gplr='git pull --rebase' +alias gpl='git pull' alias gpo='git push origin' alias gpf='git push --force' -alias gpl='git pull' +# git log aliases alias glog='git log --oneline --graph --decorate' alias gloga='git log --oneline --graph --decorate --all' -alias glod='git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' -alias glods='git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short' +alias glod='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"' +alias glods='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short' + +#termbin +alias tb='nc termbin.com 9999' + +# get error messages from journalctl +alias jerr='journalctl -p 3 -xb' +# get warning messages from journalctl +alias jwarn='journalctl -p 4 -xb' +# get critical messages from journalctl +alias jcrit='journalctl -p 2 -xb' +# get emergency messages from journalctl +alias jemerg='journalctl -p 0 -xb' + +# get status of all services +alias jstat='systemctl list-units --type=service --state=running' +# get status with failed services +alias jstatf='systemctl list-units --type=service --state=failed' + +# history +alias histg='history | grep' + +# get my ip +alias myip='curl ifconfig.me' +#TODO: get my ipv4 diff --git a/bash/bash_functions b/bash/bash_functions new file mode 100644 index 0000000..aaea6af --- /dev/null +++ b/bash/bash_functions @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +### ARCHIVE EXTRACTION +# usage: ex +function ex { + if [ -z "$1" ]; then + # display usage if no parameters given + echo "Usage: ex ." + echo " extract [path/file_name_2.ext] [path/file_name_3.ext]" + else + for n in "$@" + do + if [ -f "$n" ] ; then + case "${n%,}" in + *.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar) + tar xvf "$n" ;; + *.lzma) unlzma ./"$n" ;; + *.bz2) bunzip2 ./"$n" ;; + *.cbr|*.rar) unrar x -ad ./"$n" ;; + *.gz) gunzip ./"$n" ;; + *.cbz|*.epub|*.zip) unzip ./"$n" ;; + *.z) uncompress ./"$n" ;; + *.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar) + 7z x ./"$n" ;; + *.xz) unxz ./"$n" ;; + *.exe) cabextract ./"$n" ;; + *.cpio) cpio -id < ./"$n" ;; + *.cba|*.ace) unace x ./"$n" ;; + *) + echo "ex: '$n' - unknown archive method" + return 1 + ;; + esac + else + echo "'$n' - file does not exist" + return 1 + fi + done +fi +} + +function ensure { + if [ -z "$1" ]; then + echo "Usage: ensure " + else + if ! command -v $1 &> /dev/null + then + echo "$1 could not be found" + fi + fi +} diff --git a/bash/bashrc b/bash/bashrc index 9566b3d..c1ad5cf 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -26,7 +26,9 @@ fi unset rc -source /home/slnopriv/alacritty/extra/completions/alacritty.bash +if ! source /home/slnopriv/alacritty/extra/completions/alacritty.bash; then + echo "Failed to source alacritty completions" +fi eval "$(starship init bash)" # >>> conda initialize >>> @@ -45,7 +47,12 @@ unset __conda_setup # <<< conda initialize <<< #Source aliases source ~/.bash_aliases +source ~/.fedora_aliases export PATH="~/scripts:$PATH" +# Souecw functions +source ~/.bash_functions + + # !! Contents within this block are managed by juliaup !! case ":$PATH:" in diff --git a/bash/fedora_aliases b/bash/fedora_aliases new file mode 100644 index 0000000..b6b9fe7 --- /dev/null +++ b/bash/fedora_aliases @@ -0,0 +1,38 @@ +alias dnfs='dnf search' +alias dnfl='dnf list' +alias dnfli='dnf list installed' + +# Using sudo +alias dnfu='sudo dnf upgrade' +alias dnfi='sudo dnf install' +alias dnfr='sudo dnf remove' + +# User specific aliases and functions +alias cdpex='cd ~/Documents/Education/UniBas/FS23/pids23/exercises/pids_2023/exercises/' +alias uni23='cd ~/Nextcloud/Documents/Unibas/HS23/' +alias thoc='cd ~/Nextcloud/Documents/Unibas/FS23/thoc/' +alias inetsec='cd ~/Nextcloud/Documents/Unibas/FS23/inetsec/' +#cd into os alias +alias os='cd ~/Nextcloud/Documents/Unibas/FS23/os/' +alias pkvps='cd ~/Nextcloud/Documents/Unibas/FS23/pkvps/' +alias pids='cd ~/Nextcloud/Documents/Unibas/FS23/pids/' +alias pr23='cd ~/Documents/Education/UniBas/HS23/pr23/' +alias db23='cd ~/Documents/Education/UniBas/HS23/databases/' +alias pet23='cd ~/Documents/Education/UniBas/HS23/pethpc23/' +alias diskmath='cd ~/Documents/Education/UniBas/HS23/diskmath-tutorat23/' +alias pullbooks='rsync -av ~/Nextcloud/Books/ ~/Books' +alias pushbooks='rsync -av ~/Books/ ~/Nextcloud/Books' +alias pushfs24='rsync -uav --exclude=".*" --exclude="__*" --exclude="/venv" ~/documents/education/unibas/fs24/ ~/Nextcloud/Documents/Unibas/FS24' +alias pullfs24='rsync -uav --exclude=".*" ~/Nextcloud/Documents/Unibas/FS24/ ~/documents/education/unibas/fs24' +alias fs24l='cd ~/documents/education/unibas/fs24' +alias fs24c='cd ~/Nextcloud/Documents/Unibas/FS24' +alias sdev='ssh sebl@slenzlinger.dev' +alias sslenz='ssh fm18b_sebaschi@slenzlinger.ch' + +alias ccat='pygmentize -g' + +# list repo IDs and which .repo they belong to +alias frepos='grep -E "^\[.*]" /etc/yum.repos.d/*' + +# grep aliases +alias galias='alias | grep' diff --git a/bash/scripts/scripts/arrange_slides b/bash/scripts/scripts/arrange_slides new file mode 100755 index 0000000..84f301f --- /dev/null +++ b/bash/scripts/scripts/arrange_slides @@ -0,0 +1,19 @@ +#! /usr/bin/env bash + +filename=$1 +rmpattern=$2 +suffix=$3 +dstFolder="${PWD}/arranged" +newFilename="${filename%${rmpattern}}${suffix}.pdf" +# Make destination folder +mkdir -p ${dstFolder} + +pdfjam --nup 2x2 \ + --landscape \ + --clip 'true' \ + --delta '0cm 0cm' \ + --offset '1cm 0cm' \ + --outfile ${newFilename} ${filename} +mv ${newFilename} ${dstFolder} +# unused +# --trim '0.7cm 0cm 0.7cm 0cm' \ diff --git a/bash/scripts/scripts/arrangefai b/bash/scripts/scripts/arrangefai new file mode 100755 index 0000000..2604d28 --- /dev/null +++ b/bash/scripts/scripts/arrangefai @@ -0,0 +1,13 @@ +#! /usr/bin/env bash +file=$1 +outfile="${file%'handout.pdf'}jam4.pdf" +dst=${PWD}/jammed +mkdir -p ${dst} +pdfjam --nup 2x2 --column false \ + --landscape --offset '1.2cm 0cm' \ + --outfile ${outfile} --scale 0.95 \ + --frame true \ + $1 + +mv ${outfile} ${dst} + diff --git a/bash/scripts/scripts/chatroom b/bash/scripts/scripts/chatroom new file mode 100755 index 0000000..b01ed71 --- /dev/null +++ b/bash/scripts/scripts/chatroom @@ -0,0 +1,195 @@ +#!/usr/bin/env bash +################################################################################ +## Author: Sebastian Lenzlinger +## EMail: eswer@eswo.ch +################################################################################ + +################################################################################ +# TIPP: source this file so functions are available directly in the command line +################################################################################ +initialize () { + if [[ $# -ne 1 ]]; then + echo "Usage: initialize ''" + echo "Please only supply your name as a single string" + echo "This will be used as the branch name." + return + fi + + usrnm=$1 + + + # Create repo 'usrnm' with branch 'usrnm' + git init -b "${usrnm}" "${usrnm}" && cd "${usrnm}" + echo "Initialized git repo ${usrnm} with branch ${usrnm}" + git config --local user.name "${usrnm}" + git config --local user.email "${usrnm}@gitchat.local" + # Establish tree object + treeroot=$(git write-tree) + echo "Tree written at ref "${treeroot}"." + + # Create initial commit without parent commits + initcommit="$(echo "${usrnm} has joined the chatroom." | git commit-tree "${treeroot}")" + echo "Initial commit "${initcommit}" with message "$(git cat-file -p ${initcommit})"." + + #Set HEAD of usrnm branch to first commit + git update-ref "$(git symbolic-ref HEAD)" "${initcommit}" +} + + +post() { + if ! [[ -d "${PWD}/.git" ]]; then + echo "You must be in a git repo root to use this command!" + return + fi + + # Single quotes so can use any spacial characters that bash would expand. + if [[ $# -ne 1 ]]; then + echo "Please supply you message in single quotes!" + echo "Usage: post ''" + return + fi + + msg=$1 + + # this seems to be the way; assuming there is one tree + roottreeref=$(git log --pretty=format:%T -n 1) + if [[ -z "${roottreeref}" ]]; then + echo "NO TREE: Couldnt find tree object." + return + fi + echo "Root trees ref "${roottreeref}"" + + parents= + for p in $(git for-each-ref --format='%(objectname)' refs/heads/); do + parents+="-p ${p} " + done + echo "Parent commits ${parents}" + + # This didn't work!!! + # roottreeref=($(git cat-file --batch-all-objects --batch-check | grep tree)) + + # Put message at end so last whitespace is ignored, doesn't lead to issues + commitref="$(git commit-tree ${roottreeref} ${parents} -m "${msg}")" + echo "Current commits ref ${commitref}" + + git update-ref "$(git symbolic-ref HEAD)" "${commitref}" + echo + echo "Posted message:" + echo "${msg}" + + unset roottreeref + unset parents + unset commitref + unset msg +} + +show() { + + if ! [[ -d "${PWD}/.git" ]]; then + echo "You must be in a git repo root to use this command!" + return + fi + + # This is not correct, only follow local branches, not remote branches. + #for b in $(git branch --format '%(refname:short)'); do + #git log $b --pretty=format:'%C(bold)%an (%ar):%C(reset) %s' --reverse + #done + if [[ $# -gt 1 ]];then + echo "There is only one OPTIONAL argument: -g" + return + fi + + gopt= + if [[ $1 = "-g" ]]; then gopt="--graph"; + fi + + + git log --pretty=format:'%C(bold)%Cred%an (%Cgreen%cd):%Creset %s' \ + --date=format:'%d-%m-%y--%H:%M' ${gopt} + + +} + +# $usrto is the remote name. $usrfrom is a branch name. +disseminate () { + if ! [[ -d "${PWD}/.git" ]]; then + echo "You must be in a git repo root to use this command!" + return + fi + + if [[ $# -ne 1 ]]; then + echo "Usage: disseminate " + echo "Please supply the name of the user you wish to send your message to!" + return + fi + + usrfrom="$(git branch --show-current)" + usrto="$1" + + + # Ensure remote exists + if ! git remote get-url "$usrto" > /dev/null 2>&1; then + echo "No such remote. You must first add a remote for ${usrto}" + echo "How to add: git remote add $usrto " + return + fi + + if ! git push "${usrto}" "${usrfrom}"; then + echo "Failed to push to ${usrto}. Check permissions or network issues." + return + fi + +} +################################################################################ +# Don't use described commands. Not sure if safe. +fetch-peers() { + echo "Example to fetch all branches from a remote 'bob':" + echo "git fetch bob" +} + +pull-remote() { + echo "Example to pull changes from a specific branch on 'bob' remote:" + echo "git pull bob " +} + +info() { + echo "=================================================" + echo "Adding a remote:" + echo "=================================================" + echo "git remote add " + echo "Note that can be chosen arbitrarily" + echo + echo "=================================================" + echo "PUSHing to remote branch:" + echo "=================================================" + echo "git push " + echo "Example: Push branch 'Carol' to remote 'bob'" + echo "git push bob Carol" + echo "After this the remote 'bob' will have everything from your branch 'Carol' also on a branch called 'Carol'" + echo + echo "WARNING: Do not use 'git push Bob Carol' if you added remote 'bob' like this: 'git remote add bob ../Bob'" + echo "This only means that you are adding a remote in .git/refs/remote, not a branch on your part." + echo + echo "=================================================" + echo "Some others:" + echo "=================================================" + fetch-peers + echo + echo + pull-remote + echo + echo "END INFO" +} + + + +echo "To use the functions, source this file from the command line:" +echo "'source path/to/chatroom' or just 'source chatroom' if it is in the same directory." +echo "After this the functions are available for the duration of your bash session as if they where built-in commands!" +echo "That means to call the initialize function just type 'initialize' NOT './initialize'" +echo "You will see this message again when you source the file." +################################################################################ +# Useful for debugging +################################################################################ +alias glog="git log --oneline --graph" +alias gloga="git log --oneline --graph --all" diff --git a/bash/scripts/scripts/db23-arrange.sh b/bash/scripts/scripts/db23-arrange.sh new file mode 100755 index 0000000..2a3c609 --- /dev/null +++ b/bash/scripts/scripts/db23-arrange.sh @@ -0,0 +1,9 @@ +#! /usr/bin/bash +filename=$1 +arrangedFolder=${PWD}/arranged +newFilename=${filename:0:3}db23-arranged.pdf +echo "Arranging $filename" +/usr/bin/pdfjam --nup 2x2 --landscape --outfile $newFilename $filename +echo "Moving $new-filename to $arranged-folder" +mv $newFilename $arrangedFolder +echo "Done" diff --git a/bash/scripts/scripts/mergeindir b/bash/scripts/scripts/mergeindir new file mode 100755 index 0000000..42f2b4d --- /dev/null +++ b/bash/scripts/scripts/mergeindir @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +qpdf --empty --pages $(ls -l | grep -v '^d' | sort) -- "$1.pdf" diff --git a/bash/scripts/scripts/mergepdfs b/bash/scripts/scripts/mergepdfs new file mode 100755 index 0000000..8a351f9 --- /dev/null +++ b/bash/scripts/scripts/mergepdfs @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Check if qpdf is installed +if ! command -v qpdf &> /dev/null; then + echo "Error: qpdf could not be found. Please install qpdf." + exit 1 +fi + +# Target PDF filename +output_pdf="$1.pdf" +if [[ -z "$1" ]]; then + echo "Usage: $0 " + exit 1 +fi + +# Prepare an array to hold the PDF files +pdf_files=() +shopt -s nullglob +for file in *.pdf; do + pdf_files+=("$file") +done + +# Check if we found any PDF files +if [[ ${#pdf_files[@]} -eq 0 ]]; then + echo "No PDF files found in the current directory." + exit 1 +fi + +# Sort files just in case +IFS=$'\n' pdf_files=($(sort <<<"${pdf_files[*]}")) +unset IFS + +# Run qpdf to combine PDF files +qpdf --empty --pages "${pdf_files[@]}" -- "$output_pdf" + +echo "PDF files combined into $output_pdf" + diff --git a/bash/scripts/scripts/pr23-arrange.sh b/bash/scripts/scripts/pr23-arrange.sh new file mode 100755 index 0000000..8dde6dc --- /dev/null +++ b/bash/scripts/scripts/pr23-arrange.sh @@ -0,0 +1,10 @@ +#! /usr/bin/bash + +filename=$1 +arrangedFolder=${PWD}/arranged +newFilename=${filename}-pr23-arranged.pdf +echo "Arranging $filename" +/usr/bin/pdfjam --nup 2x1 --landscape --outfile $newFilename $filename +echo "Moving $newFilename to $arrangedFolder" +mv $newFilename $arrangedFolder +echo "Done" diff --git a/git/gitconfig b/git/gitconfig index 5d93e68..256f4bd 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -1,3 +1,10 @@ [user] email = 74497638+sebaschi@users.noreply.github.com name = Sebastian Lenzlinger +[http] + sslVerify = false +[filter "lfs"] + clean = git-lfs clean -- %f + smudge = git-lfs smudge -- %f + process = git-lfs filter-process + required = true