diff --git a/dotfiles/.p10k.zsh b/dotfiles/.config/zsh/.p10k.zsh similarity index 100% rename from dotfiles/.p10k.zsh rename to dotfiles/.config/zsh/.p10k.zsh diff --git a/dotfiles/.zshrc b/dotfiles/.config/zsh/.zshrc similarity index 52% rename from dotfiles/.zshrc rename to dotfiles/.config/zsh/.zshrc index 334af8a..13de64d 100644 --- a/dotfiles/.zshrc +++ b/dotfiles/.config/zsh/.zshrc @@ -2,10 +2,13 @@ if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]] source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" fi -HISTSIZE=10000 -SAVEHIST=10000 +HISTSIZE=10000000 +SAVEHIST=10000000 HISTFILE=~/.cache/zsh/.histfile +# https://superuser.com/questions/613685/how-stop-zsh-from-eating-space-before-pipe-symbol +ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&' + if [[ -v LAPTOP ]]; then export ZSH="/usr/share/oh-my-zsh" ZSH_CUSTOM="/usr/share" @@ -24,19 +27,31 @@ ENABLE_CORRECTION="true" # DISABLE_UNTRACKED_FILES_DIRTY="true" # ZSH_CUSTOM=/path/to/new-custom-folder -#plugins=(git vi-mode zsh-autosuggestions) +# plugins=(git vi-mode zsh-autosuggestions) plugins=(git vi-mode) -source $ZSH/oh-my-zsh.sh +# unsetopt EXTENDED_HISTORY + +export ZSH_COMPDUMP="$XDG_CACHE_HOME"/zsh/zcompdump-"$HOST-$ZSH_VERSION" + +source "$ZSH"/oh-my-zsh.sh + +setopt HIST_SAVE_NO_DUPS +setopt HIST_IGNORE_ALL_DUPS +# setopt HIST_REDUCE_BLANKS +# unsetopt SHARE_HISTORY +# setopt INC_APPEND_HISTORY +# unsetopt EXTENDED_HISTORY bindkey -v function zle-keymap-select { - if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then - echo -ne '\e[1 q' - elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then - echo -ne '\e[5 q' - fi + if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then + echo -ne '\e[1 q' + elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || + [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then + echo -ne '\e[5 q' + fi } zle -N zle-keymap-select @@ -45,7 +60,8 @@ zle-line-init() { zle -K viins echo -ne "\e[5 q" - echoti smkx # Del key: https://git.suckless.org/st/file/FAQ.html + # https://git.suckless.org/st/file/FAQ.html -> Why doesn't the Del key work in some programs? + echoti smkx } zle -N zle-line-init @@ -53,8 +69,9 @@ zle -N zle-line-init echo -ne '\e[5 q' preexec() { echo -ne '\e[5 q' ;} +# Edit in vim: https://unix.stackexchange.com/a/90529 export VISUAL="nvim" -autoload edit-command-line; zle -N edit-command-line +autoload -U edit-command-line; zle -N edit-command-line bindkey '^E' edit-command-line autoload -U history-search-end @@ -66,9 +83,16 @@ bindkey "^[[B" history-beginning-search-forward-end function zle-line-finish () { echoti rmkx } zle -N zle-line-finish -source ~/.zshrc_aliases +source "$ZDOTDIR"/.zshrc_aliases -[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh +[[ ! -f ${ZDOTDIR:-~}/.p10k.zsh ]] || source ${ZDOTDIR:-~}/.p10k.zsh bindkey -s '^f' 'cd "$(dirname "$(fzf)")"\n' bindkey -s '^o' 'xdg-open "$(fzf)"\n' + +# https://unix.stackexchange.com/questions/693118/trim-trailing-newline-from-pasted-text-in-zsh +bracketed-paste() { + zle .$WIDGET && LBUFFER=${LBUFFER%$'\n'} +} + +zle -N bracketed-paste diff --git a/dotfiles/.config/zsh/.zshrc_aliases b/dotfiles/.config/zsh/.zshrc_aliases new file mode 100644 index 0000000..2d0de34 --- /dev/null +++ b/dotfiles/.config/zsh/.zshrc_aliases @@ -0,0 +1,320 @@ +#!/bin/sh + +alias mpvgui='mpv --player-operation-mode=pseudo-gui' + +alias ll='ls -l' +alias la='ls -A' +alias l='ls -CF' +alias lh='ls -lh' + +alias vim='nvim' +alias svim='sudo nvim' + +alias ga='git add' +alias gaa='git add .' +alias gaaa='git add -A' +alias gc='git commit' +alias gcm='git commit -m' +alias gd='git diff' +alias gi='git init' +alias gl='git log' +alias gp='git pull' +alias gpsh='git push' +alias gss='git status -s' +# Undo commit (https://stackoverflow.com/questions/2845731/how-to-uncommit-my-last-commit-in-git) +alias gundo='git reset --soft HEAD~1' +alias gck='git checkout' +alias wget=wget --hsts-file="$XDG_DATA_HOME/wget-hsts" + +gacp() { + git add . + local var="$@" + git commit -m "$var" + git push +} + +gac() { + git add . + local var="$@" + git commit -m "$var" +} + +alias exiftcl='exiftool -all=' +alias exift='exiftool' + +alias upgraded='grep -i upgraded /var/log/pacman.log | tac | less' +alias installed='grep -i installed /var/log/pacman.log | tac | less' + +# https://archlinux.org/mirrorlist/ +alias mirrors='reflector --country Brazil,Chile,Colombia --protocol https --sort rate --save /etc/pacman.d/mirrorlist' + +# https://stackoverflow.com/questions/9449778/what-is-the-benefit-of-using-instead-of-backticks-in-shell-scripts# +alias open='xdg-open $(fzf)' +alias o='xdg-open' + +alias zat='zathura --fork' + +alias trash-dir='cd $HOME/.local/share/Trash' + +#alias fd='cd "$(dirname "$(fzf)")"' + +alias val='valgrind --leak-check=full ./listdir prueba/ > valgrind.output 2>&1' + +alias pampero='ssh slococo@pampero.itba.edu.ar' + +alias bd='systemctl start postgresql.service' + +alias copy='xclip -selection clipboard' + +function compile() { + sudo make clean && sudo make install +} + +function rcomp() { + local file="${1//.rmd/}" + R -e "rmarkdown::render('$file.rmd', 'pdf_document')" && op $file.pdf +} + +function cl() { + nasm -f elf $1 + local program="${1//.asm/}" + ld -melf_i386 $program.o -o $program + if [[ $# -ge 3 ]]; then + ./$program "${@:3}" + else + ./$program + fi +} + +function cld() { + nasm -f elf $1 && nasm -f elf $2 + local program="${1//.asm/}" + local library="${2//.asm/}" + ld -melf_i386 $program.o $library.o -o $program + if [[ $# -ge 3 ]]; then + ./$program "${@:3}" + else + ./$program + fi +} + +function asc() { + nasm -f elf32 $1 + gcc -c -m32 $2 + local assem="${1//.asm/}" + local cprog="${2//.c/}" + gcc -m32 -no-pie $assem.o $cprog.o -o $assem + if [[ $# -ge 3 ]]; then + ./$assem "${@:3}" + else + ./$assem + fi +} + +function ascn() { + nasm -f elf32 $1 + local assem="${1//.asm/}" + gcc -m32 -no-pie $assem.o -o $assem + if [[ $# -ge 2 ]]; then + ./$assem "${@:2}" + else + ./$assem + fi +} + +function ascld() { + nasm -f elf32 $1 + gcc -c -m32 $2 + local assem="${1//.asm/}" + local cprog="${2//.c/}" + ld -melf_i386 $assem.o $cprog.o -o $assem + if [[ $# -ge 3 ]]; then + ./$assem "${@:3}" + else + ./$assem + fi +} + +function gci() { + echo "Copy after 'git@github.com:'" + git clone git@itba.github.com:$1 +} + +function gcir() { + echo "Copy after 'git@github.com:'" + git remote add origin git@itba.github.com:$1 +} + +function gcn() { + echo "Copy after 'git@github.com:'" + git clone git@github.com:$1 +} + +function gcin() { + echo "Copy after 'git@github.com:'" + git remote add origin git@github.com:$1 +} + +# Start an ssh-agent and run KeePass in order to cache the ssh passwords +function gith() { + #eval $(ssh-agent) + keepass & + ~/.local/bin/waitForSSH & +} + +# https://vsupalov.com/docker-shared-permissions/ +# https://medium.com/redbubble/running-a-docker-container-as-a-non-root-user-7d2e00f8ee15 +#alias dcom='docker run -v ${PWD}:/root -ti -w /root agodio/itba-so:1.0 ${1}' +#alias dcom='docker run -v ${PWD}:/root --security-opt seccomp:unconfined -ti agodio/itba-so:1.0' +alias dcom='docker run -v ${PWD}:/root --security-opt seccomp:unconfined --user $(id -u):$(id -g) -w /root -ti agodio/itba-so:1.0' +#alias dcom='docker run -v ${PWD}:/root --security-opt seccomp:unconfined --user $(id -u):$(id -g) -w /root --name TPE-ARQUI -ti agodio/itba-so:1.0' + +alias dcr='checkIfStarted' + +function dcreate() { + echo "Do you want to create a container with root or user (as the owner)?" + chosen=$(echo "root\nuser" | dmenu) + echo "Enter a name for the container" + read name + if [ $chosen = "root" ]; then + docker run -v ${PWD}:/root --security-opt seccomp:unconfined -w /root --name $name -ti agodio/itba-so:1.0 + else + docker run -v ${PWD}:/root --security-opt seccomp:unconfined --user $(id -u):$(id -g) -w /root --name $name -ti agodio/itba-so:1.0 + fi +} + +function checkIfStarted() { + if systemctl status docker | grep -q "inactive"; then + systemctl start docker + fi +} + +# https://stackoverflow.com/a/61390489 +function docom() { + local dockerID=`docker ps -l -q` + docker start $dockerID > /dev/null + docker exec -it $dockerID $@ + docker stop $dockerID > /dev/null +} + +function dcrun() { + local dockerID=`docker ps -l -q` + docker start $dockerID > /dev/null + docker exec -it $dockerID bash -c 'make all 2>&1 1>/dev/null | grep --color -iP "\^|warning:|error:|"' + docker stop $dockerID > /dev/null + ./run.sh +} + +function dcmake() { + local dockerID=`docker ps -l -q` + docker start $dockerID > /dev/null + docker exec -it $dockerID bash -c 'make all 2>&1 1>/dev/null | grep --color -iP "\^|warning:|error:|"' + docker stop $dockerID > /dev/null +} + +function dcstacho() { + checkIfStarted + #echo `docker ps -a | awk '{ print $12 }'` + #read line + #if [ $line -eq 2 ]; then + # local dockerID=`docker ps -a | awk 'NR==2 { print $12 }'` + #else + # local dockerID=`docker ps -a | awk 'NR==3 { print $12 }'` + #fi + #local dockerID=$(docker ps -a | awk -F"\t" '{print $12}' | tail -n +2 | dmenu) + local dockerID=$(docker ps -a --format "{{.Names}}" | dmenu) + docker start $dockerID > /dev/null + #docker exec -it $dockerID bash -c 'make all 2>&1 1>/dev/null | grep --color -iP "\^|warning:|error:|"' + #docker stop $dockerID > /dev/null + #./run.sh + docker start $dockerID > /dev/null + docker exec -it $dockerID bash $@ +} + +function dcruntpe() { + checkIfStarted + local dockerID='TPE-ARQUI' + docker start $dockerID > /dev/null + docker exec -it $dockerID bash -c 'make all 2>&1 1>/dev/null | grep --color -iP "\^|warning:|error:|"' + docker stop $dockerID > /dev/null + ./run.sh +} + +function dcgdbtpe() { + checkIfStarted + local dockerID='TPE-ARQUI-GDB' + docker start $dockerID > /dev/null + docker exec -it $dockerID bash -c 'make all 2>&1 1>/dev/null | grep --color -iP "\^|warning:|error:|"' + docker stop $dockerID > /dev/null + ./run.sh gdb +} + +function dcstatpe() { + checkIfStarted + local dockerID='TPE-ARQUI-GDB' + docker start $dockerID > /dev/null + docker exec -it $dockerID bash $@ +} + +function dcstotpe() { + local dockerID='TPE-ARQUI-GDB' + docker stop $dockerID > /dev/null +} + +function dcstatpe2() { + checkIfStarted + local dockerID='TPE-ARQUI' + docker start $dockerID > /dev/null + docker exec -it $dockerID bash $@ +} + +function dcsta() { + checkIfStarted + #local dockerID=`docker ps -l -q` + local dockerID=`docker ps -l` + docker start $dockerID > /dev/null + docker exec -it $dockerID bash $@ +} + +function dcsto() { + local dockerID=`docker ps -l -q` + docker stop $dockerID > /dev/null +} + +function extract { + if [ -z "$1" ]; then + echo "Usage: extract ." + else + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xvjf ../$1 ;; + *.tar.gz) tar xvzf ../$1 ;; + *.tar.xz) tar xvJf ../$1 ;; + *.lzma) unlzma ../$1 ;; + *.bz2) bunzip2 ../$1 ;; + *.rar) unrar x -ad ../$1 ;; + *.gz) gunzip ../$1 ;; + *.tar) tar xvf ../$1 ;; + *.tbz2) tar xvjf ../$1 ;; + *.tgz) tar xvzf ../$1 ;; + *.zip) unzip ../$1 ;; + *.Z) uncompress ../$1 ;; + *.7z) 7z x ../$1 ;; + *.xz) unxz ../$1 ;; + *.exe) cabextract ../$1 ;; + *) echo "extract: '$1' - unknown archive method" ;; + esac + else + echo "$1 - file does not exist" + fi + fi +} + +function maketar() { + tar cvzf "${1%%/}.tar.gz" "${1%%/}/" +} + +function makezip() { + zip -r "${1%%/}.zip" "$1" +} + diff --git a/dotfiles/.zshrc_exports b/dotfiles/.zshrc_exports deleted file mode 100644 index e0c33d1..0000000 --- a/dotfiles/.zshrc_exports +++ /dev/null @@ -1,22 +0,0 @@ -export TERM=st-256color -export TERMINAL=st - -export GOPATH=$HOME/.config/go - -export CM_SELECTIONS="clipboard" -export CM_DEBUG=1 -export CM_OUTPUT_CLIP=0 -export CM_MAX_CLIPS=10 -export CM_IGNORE_WINDOW="Bitwarden" - -export _JAVA_AWT_WM_NONREPARENTING=1 -export PAGER='nvimpager -p' - -export R_HOME_USER=$HOME/.config/R -export R_PROFILE_USER=$HOME/.config/R/.Rprofile -export R_LIBS_USER=$HOME/.config/R/library -export R_HISTFILE=$HOME/.config/R/.Rhistory - -export QT_QPA_PLATFORMTHEME=gtk2 - -export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1