aboutsummaryrefslogblamecommitdiffstats
path: root/bashrc-laptop
blob: 9cc759265583bdd48afd00bb44cb892e8abb0c82 (plain) (tree)














































































































                                                                                                                                                                                                                                
                                       










































































































































































































































































                                                                                                                                                                                                                                                  
# completion as advised by arch wiki
complete -cf sudo man which

# utility functions
_have() { type "$1" &>/dev/null; }
_source_if() { [[ -r "$1" ]] && source "$1"; }

# _have setxkbmap && test -n "$DISPLAY" && setxkbmap -option caps:escape &>/dev/null

_have xset && xset r rate 300 30
_have setxkbmap && setxkbmap -option ctrl:nocaps
_have setxkbmap && setxkbmap -layout gb
_have pandoc && . <(pandoc --bash-completion)
_source_if ~/.config/todo_completion

shopt -s globstar
shopt -s dotglob
shopt -s extglob

# reduce history size
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=20000
export HISTFILESIZE=200000

# Setting PATH
export PATH=~/.cargo/bin:$PATH
export PATH=~/bin/:$PATH
export PATH="$PATH:/opt/nvim-linux64/bin"
#export PATH="$HOME/gems/bin:$PATH"
export PATH="$HOME/go/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="/usr/local/go/bin:$PATH"
export BORG_PASSCOMMAND='pass show borg-passphrase'
export DOTFILES_DIR="$HOME/dotfiles"
export DOCUMENTS="$HOME/Documents"
export NOTES="$HOME/Documents/Notes"
export LEDGER_FILE="$HOME/Budget/hledger/budget.ledger"
#export TERM="screen-256color" arch wiki says not to set this here.
export LESS="-iMRS -x2"
export RANGER_LOAD_DEFAULT_RC="FALSE"
export FZF_DEFAULT_COMMAND="rg --files --hidden --glob '!.git' "
# export FZF_DEFAULT_COMMAND='ag -l --path-to-ignore ~/.ignore --nocolor --hidden -g ""'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND"
export EDITOR=vim
export VISUAL=vim
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

export TODOTXT_DEFAULT_ACTION=ls

export OLLAMA_MODELS="$HOME/ai_models/ollama/"

# completions
if [ -f /usr/share/bash-completion/completions/pass ]; then
    . /usr/share/bash-completion/completions/pass
fi


# export PS1='bash-\v-\u@\h \W\$ '
# export PS1='\[\033[38;5;208m\]\u@\h:\w\$\[\033[0m\] '
#export PS1='\[\033[01;32m\]\u@\h:\w\$\[\033[0m\] '

export PS1='\[\033[01;36m\][\u@\h\[\033[01;37m\] \W\[\033[01;36m\]]\$\[\033[00m\] '

# stripe completion
source ~/.stripe/stripe-completion.bash

# vi mode
#set -o vi

# prevent clobbering of files
# echo "output" >| file.txt to do it manually
set -o noclobber

#alias vim='/usr/bin/nvim'
#alias vi='/usr/bin/vim'
# export ALTERNATE_EDITOR=""
# export EDITOR="emacsclient -t"                  # $EDITOR opens in terminal
# export VISUAL="emacsclient -c -a emacs"         # $VISUAL opens in GUI mode

# from https://wiki.archlinux.org/title/Beets
#eval "$(beet completion)"

# aliases
alias am='append_to_masterlist'
alias annex-sync='cd ~/annex/ && git annex sync && cd -'
alias bglist='borg list ssh://u423613@u423613.your-storagebox.de:23/./backups/matt_desktop'
alias blog="cd ~/code/html/yulqen.org/"
alias brandom='beet play "$(beet random -p)"'
alias bud="cd ~/Budget/hledger/"
alias c='printf "\e[H\e[2J"'
alias dot="cd $DOTFILES_DIR"
alias emacsclient="emacsclient -c &"
alias getip="curl ifconfig.me"
alias gitrepos="ssh git@joannalemon.com \"tree -L 2 repositories\""
alias gloga='git log --oneline --decorate --graph --all'
alias _hl_bal_lastmonth='hledger bal --period "this month" --depth 3 Expenses'
alias jrnl="/home/lemon/src/virtualenvs/jrnl/bin/jrnl"
alias k5days='khal list today 5 days'
alias ll="ls -larth" # sort by modified
alias ls="ls --color=auto"
alias mountmusic='sudo sshfs -o IdentityFile=/home/lemon/.ssh/id_ed25519,default_permissions,allow_other lemon@192.168.1.10:/mnt/music /mnt/music'
alias notesbackup='duplicity --encrypt-key 19014642A9FCD633B886B8F59C9841C3EF4E0B8E ~/Documents/Notes/ sftp://git@joannalemon.com:2222/notesbackup'
alias notes="cd $HOME/Documents/Notes/"
alias notetasks='find $HOME/Documents/Notes -type f -iname 'tasks.md' -print0 | xargs -0 batcat'
alias pacdel="pacman -Qq | fzf --multi --preview 'pacman -Qi {1}' | xargs -ro sudo pacman -Rns"
alias pacget="pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S"
alias pacpreview="pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'"
alias qn2firefox='pandoc /home/lemon/Documents/Notes/quicknote.md -o /tmp/quicknote.html && firefox /tmp/quicknote.html'
alias qnarchive='mkdir /tmp/quicknotes && cp ~/code/html/yulqen.org/content/techjournal/quicknote_capture_* /tmp/quicknotes && cp ~/Documents/Notes/quicknote.md /tmp/quicknotes && tar czf quicknotes.tgz -C /tmp/quicknotes .'
alias quickqr='qrencode -t ansiutf8 $1'
alias rnr=read_and_review
alias ststatus='curl -X GET -H "X-API-Key:giuDMYqvFhM2G5ziuFFXLEpC5SjdpgzF"  http://localhost:8384/rest/db/status?folder=eahtt-9qkuk|jq'
alias sync-tunnel='ssh -N -L 9090:127.0.0.1:8384 syncthing@syncthing-ct.banded-neon.ts.net'
alias tcomptoday='task end.after:today-1d completed'
alias temp='cd $(mktemp -d)'
alias thisweek='khal list today 5days -d google_timebox'
alias thomeprojects='task _unique project|grep "h\."'
alias tkilled="task +killlist list"
alias tl="/home/lemon/Documents/Notes/todo/todo.sh list"
alias to="todo.sh"
alias tprojects="task rc.list.all.projects=1 projects"
alias ttagged="task tags.any: list"
alias ttags="task rc.list.all.tags=1 tags"
alias ttoday="task ml_due_or_scheduled_today"
alias t="todo.sh"
alias tuntagged="task tags.none: list"
alias tworkprojects='task _unique project|grep "w\."'
alias upload_datafile_surgetracker='scp /home/lemon/Documents/Notes/Projects/Surgetracker/resources/master_add_data.csv surge@64.227.37.12:code/surgetracker/datafiles'
alias vi='vim'
alias weather='curl wttr.in'
alias xclip='xclip -selection c'
alias xterm-blue='xterm -bg Dark\ Slate\ Blue -fg white -fa -*-fixed-*-*-*-*-20-*-*-*-*-*-iso8859-*'
alias xterm-lastmiles='xterm -bg black -fg white -fa terminus'

grepfishhistory () {
    grep "$1" ~/.local/share/fish/fish_history |cut -f3- -d' '
}


# taskwarrior tickler file - https://cs-syd.eu/posts/2015-06-28-gtd-with-taskwarrior-part-3-tickling
tickle () {
    deadline=$1
    shift
    task add wait:$deadline $@
}

# taskwarrior read and review (ensure you have html-xml-utils package installed)
webpage_title (){
	curl -s "$@" | hxselect -s '\n' -c 'title' 2>/dev/null
}

read_and_review (){
    link="$1"
    title=$(webpage_title $link)
    echo $title
    descr="\"Read and review: $title\""
    id=$(task add pro:h.reading "$descr" | sed -n 's/Created task \(.*\)./\1/p')
    task "$id" annotate "$link"
}



# gpg
export GPG_TTY="$(tty)"
gpgconf --launch gpg-agent

# find file tagged using filetags
_find_tagged ()
{
    find ~/Documents -name "*--*$1*"
}

# ssh - from https://wiki.archlinux.org/title/SSH_keys#SSH_agents
# if ! pgrep -u "$USER" ssh-agent > /dev/null; then
#     ssh-agent -t 1h > "$XDG_RUNTIME_DIR/ssh-agent.env"
# fi
# if [[ ! -f "$SSH_AUTH_SOCK" ]]; then
#     source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
# fi

# if ! [[ -v SSH_AUTH_SOCK ]] && ! [[ -v SSH_AGENT_PID ]]; then
#     echo "It looks like the env variables are not set."
#     eval "$(ssh-agent -s)"
#     ssh-add ~/.ssh/id_ed25519  # Add your key manually
#     export SSH_AUTH_SOCK=$SSH_AUTH_SOCK
#     export SSH_AGENT_PID=$SSH_AGENT_PID
# fi

if ! [ -v SSH_AUTH_SOCK ] && ! [ -v SSH_AGENT_PID ]; then
    echo "Starting ssh-agent..."
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519  # Add your key manually
fi

# bind '"\C-r": "\C-x1\e^\er"'
# bind -x '"\C-x1": __fzf_history';

__fzf_history ()
{
__ehc $(history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "!$1"')
}

__ehc()
{
if
        [[ -n $1 ]]
then
        bind '"\er": redraw-current-line'
        bind '"\e^": magic-space'
        READLINE_LINE=${READLINE_LINE:+${READLINE_LINE:0:READLINE_POINT}}${1}${READLINE_LINE:+${READLINE_LINE:READLINE_POINT}}
        READLINE_POINT=$(( READLINE_POINT + ${#1} ))
else
        bind '"\er":'
        bind '"\e^":'
fi
}

# fkill - kill processes - list only the ones you can kill. Modified the earlier script.
fkill() {
    local pid 
    if [ "$UID" != "0" ]; then
        pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
    else
        pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
    fi  

    if [ "x$pid" != "x" ]
    then
        echo $pid | xargs kill -${1:-9}
    fi  
}

# fshow - git commit browser

fshow() {
  git log --graph --color=always \
      --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
  fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
      --bind "ctrl-m:execute:
                (grep -o '[a-f0-9]\{7\}' | head -1 |
                xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF'
                {}
FZF-EOF"
}


tm() {
  [[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
  if [ $1 ]; then
    tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
  fi
  session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) &&  tmux $change -t "$session" || echo "No sessions found."
}

tmuxkillf() {
    local sessions
    sessions="$(tmux ls | fzf --exit-0 --multi)" || return $?
    local i
    for i in "${sessions[@]}"
    do
        if [[ $i =~ ([^:]*):.* ]]; then
            echo "Killing ${BASH_REMATCH[1]}"
            tmux kill-session -t "${BASH_REMATCH[1]}"
        fi
    done
}

fman() {
    man -k . | fzf -q "$1" --prompt='man> '  --preview $'echo {} | tr -d \'()\' | awk \'{printf "%s ", $2} {print $1}\' | xargs -r man | col -bx | bat -l man -p --color always' | tr -d '()' | awk '{printf "%s ", $2} {print $1}' | xargs -r man
}
# Get the colors in the opened man page itself
#export MANPAGER="sh -c 'col -bx | bat -l man -p --paging always'"

#source $HOME/secrets

# Functions

##############################################################
# Quick way to create a new blog post with Hugo from wherever
# on the filesystem.
# Used ChatGPT to get the substitution and escaping correct.
# Called with a single string argument.
# ############################################################

function newpost() {
  if [[ $# -ne 1 ]]; then echo "Give me the title!"; return; fi
  title="$1"
  # convert title to lowercase and replace spaces with hyphens for the slug
  slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
  # create the new post file with Hugo
  cd $HOME/code/html/yulqen.org
  post_path="content/blog/$slug.md"
  hugo new "$post_path"
  # update the front matter with the original title string
  echo "Looking for $post_path..."
  awk -v title="$title" '{gsub(/title: .*/, "title: \""title"\"")}1' "$post_path" > tmp && mv tmp "$post_path"
  vim $post_path
}

###################################################################
# To output in cat, just call todj.
# To enable editing the files in vim, call todj vim.
# You can use less or any other tool to display the text if you wish
# Arguments:
# 	None
#	Output:
#		Writes to stdout or opens program passed as first argument
###################################################################
todj () {
  CMD=${1:-"cat"}
  $CMD $(find /home/lemon/Documents/Notes/journal/home -name "*$(date '+%Y-%m-%d')*")
}

append_to_masterlist() {
  ml=~/Documents/Notes/todo/masterlist.txt
  echo "$1" >> "$ml"
  cat "$ml"
}

# Colors for ls - yellow directories
# export LS_COLORS="$LS_COLORS:di=1;33"
# Install Ruby Gems to ~/gems


# note() {
#   printf "%s\n" "$(date +"%Y-%m-%d: ") $1" >> notes.txt
# }

# log() {
#   printf "%s\n" "$(date +"%Y-%m-%d: ") $*" >> ~/Documents/Notes/Scratch/scratchpad.md
# }

log() {
  printf "%s\n" "$(date +"%Y-%m-%d %A: ") $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

doo() {
  printf "%s\n" "TODO: $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

idea() {
  printf "%s\n" "IDEA: $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

n() {
  printf "%s\n" "NOTE: $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

toread() {
  printf "%s\n" "TOREAD: $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

flag() {
  printf "%s\n" "FLAG: $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

consider() {
  printf "%s\n" "CONSIDER: $*" >> ~/Documents/Notes/Scratch/scratchpad.txt
}

# get best audio of YouTube file or playlist (just use the right URL)
ytmp3 () {
  if [ -z "$1" ]; then print "I need a valid YouTube URL.\n"; fi
  cd ~/Downloads/music && yt-dlp -f 'ba' -x --audio-format mp3 "$1" -o '%(title)s.%(ext)s' && cd - || return
}

ytmp3-split-to-chapters() {
  if [ -z "$1" ]; then print "I need a valid YouTube URL.\n"; fi
    yt-dlp -f 'bestaudio' -x --audio-format mp3 --split-chapters -o '%(title)s.%(ext)s' "$1" && cd - || return
}

eval "$(direnv hook bash)"

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

. "$HOME/.local/share/../bin/env"