aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-12 21:26:38 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-12 21:26:38 +0100
commit33a99ad4c66efd0124faef69ee149460c8e21f6b (patch)
tree1b5f769943eb7f6f77e9ee129e78f548dd23a786
parent252d2531b10766bd644514f0f44dc5327e8fe064 (diff)
Cleans up bash config
-rw-r--r--bashrc159
1 files changed, 49 insertions, 110 deletions
diff --git a/bashrc b/bashrc
index 0d2752d..76092ee 100644
--- a/bashrc
+++ b/bashrc
@@ -1,8 +1,26 @@
# 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 xsetkbmap && setxkbmap -option ctrl:nocaps
+_have pandoc && . <(pandoc --bash-completion)
+
+shopt -s globstar
+shopt -s dotglob
+shopt -s extglob
+
# reduce history size
-export HISTCONTROL=ignoreboth
+export HISTCONTROL=ignoreboth:erasedups
+export HISTSIZE=20000
+export HISTFILESIZE=200000
+
# Setting PATH
export PATH=~/.cargo/bin:$PATH
@@ -13,6 +31,19 @@ export PATH="$HOME/.local/share/gem/ruby/3.0.0/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 OLLAMA_MODELS="$HOME/ai_models/ollama/"
@@ -21,7 +52,6 @@ if [ -f /usr/share/bash-completion/completions/pass ]; then
. /usr/share/bash-completion/completions/pass
fi
-HISTSIZE=20000
# export PS1='bash-\v-\u@\h \W\$ '
# export PS1='\[\033[38;5;208m\]\u@\h:\w\$\[\033[0m\] '
@@ -41,19 +71,16 @@ set -o noclobber
#alias vim='/usr/bin/nvim'
#alias vi='/usr/bin/vim'
-export EDITOR=vim
# export ALTERNATE_EDITOR=""
# export EDITOR="emacsclient -t" # $EDITOR opens in terminal
# export VISUAL="emacsclient -c -a emacs" # $VISUAL opens in GUI mode
-# openai keys
-source $HOME/Documents/sync/openai_key
-
-# completion for beets
# from https://wiki.archlinux.org/title/Beets
#eval "$(beet completion)"
# aliases
+alias c='printf "\e[H\e[2J"'
+alias temp='cd $(mktemp -d)'
alias am='append_to_masterlist'
alias annex-sync='cd ~/annex/ && git annex sync && cd -'
alias blog="cd ~/code/html/yulqen.org/"
@@ -63,10 +90,8 @@ 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 hd='openai_data'
-alias h='hey_openai'
+alias dot="cd $DOTFILES_DIR"
alias _hl_bal_lastmonth='hledger bal --period "this month" --depth 3 Expenses'
-alias hn='curl hkkr.in'
alias k5days='khal list today 5 days'
alias khal="$HOME/src/virtualenvs/khal-venv/bin/khal"
alias khard="$HOME/src/virtualenvs/khal-venv/bin/khard"
@@ -80,8 +105,6 @@ alias pacget="pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro 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 rem1='ssh joannalemon.com rem -c+a1 -w140 -m'
-alias rem2='ssh joannalemon.com rem -c+a2 -w140 -m'
alias sync-tunnel='ssh -N -L 9090:127.0.0.1:8384 syncthing@syncthing-ct.banded-neon.ts.net'
alias ststatus='curl -X GET -H "X-API-Key:giuDMYqvFhM2G5ziuFFXLEpC5SjdpgzF" http://localhost:8384/rest/db/status?folder=eahtt-9qkuk|jq'
alias tcomptoday='task end.after:today-1d completed'
@@ -101,23 +124,12 @@ alias vdirsyncer="$HOME/src/virtualenvs/khal-venv/bin/vdirsyncer"
alias vi='vim'
alias weather='curl wttr.in'
alias xclip='xclip -selection c'
+alias rnr=read_and_review
grepfishhistory () {
grep "$1" ~/.local/share/fish/fish_history |cut -f3- -d' '
}
-# Environment variables
-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 NOTES="$HOME/Documents/Notes"
-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 FZF_DEFAULT_OPTS="--preview='bat --color=always {}' --bind shift-up:preview-page-up,shift-down:preview-page-down --color info:108,prompt:109,spinner:108,pointer:168,marker:168"
-#export FZF_DEFAULT_OPTS="--preview='--bind shift-up:preview-page-up,shift-down:preview-page-down --color info:108,prompt:109,spinner:108,pointer:168,marker:168"
# taskwarrior tickler file - https://cs-syd.eu/posts/2015-06-28-gtd-with-taskwarrior-part-3-tickling
tickle () {
@@ -140,7 +152,6 @@ read_and_review (){
task "$id" annotate "$link"
}
-alias rnr=read_and_review
# gpg
@@ -161,10 +172,19 @@ _find_tagged ()
# source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
# fi
-eval "$(ssh-agent -s)"
-ssh-add ~/.ssh/id_ed25519 # Add your key manually
-# add other ssh-add lines for other keys if necessary!
+# 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';
@@ -204,23 +224,8 @@ fkill() {
fi
}
-# fco_preview - checkout git branch/tag, with a preview showing the commits between the tag/branch and HEAD
-fco_preview() {
- local tags branches target
- branches=$(
- git --no-pager branch --all \
- --format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \
- | sed '/^$/d') || return
- tags=$(
- git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}') || return
- target=$(
- (echo "$branches"; echo "$tags") |
- fzf --no-hscroll --no-multi -n 2 \
- --ansi --preview="git --no-pager log -150 --pretty=format:%s '..{2}'") || return
- git checkout $(awk '{print $2}' <<<"$target" )
-}
-
# fshow - git commit browser
+
fshow() {
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
@@ -232,20 +237,6 @@ fshow() {
FZF-EOF"
}
-# ftags - search ctags
-ftags() {
- local line
- [ -e tags ] &&
- line=$(
- awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' tags |
- cut -c1-80 | fzf --nth=1,2
- ) && ${EDITOR:-vim} $(cut -f3 <<< "$line") -c "set nocst" \
- -c "silent tag $(cut -f2 <<< "$line")"
-}
-
-# tm - create new tmux session, or switch to existing one. Works from within tmux too. (@bag-man)
-# `tm` will allow you to select your tmux session via fzf.
-# `tm irc` will attach to the irc session (if it exists), else it will create it.
tm() {
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
@@ -314,56 +305,6 @@ todj () {
$CMD $(find /home/lemon/Documents/Notes/journal/home -name "*$(date '+%Y-%m-%d')*")
}
-#########################################################################
-# This function takes two arguments as strings. The idea is to enable
-# passing file data into the function, such as a csv file or some code.
-# Call like this openai_data "Please optimise the following function in
-# python" "$(</path/to/file)" This is supposed to be a good way to read a
-# file's contents in bash
-# Arguments:
-# Text prompt
-# File contents
-# Output:
-# Writes to stdout
-#########################################################################
-openai_data() {
- if [[ $# -ne 2 ]]; then echo "Give me two params!"; return; fi
-
- text_prompt="$1"
- data="$2"
- prompt="${text_prompt}: ${data}"
- json=$(jq -n --arg p "$data" '{model: "gpt-3.5-turbo", messages: [{role: "user", content: $p}], temperature: 0.7}')
- local gpt=$(curl https://api.openai.com/v1/chat/completions -s \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer $OPENAI_KEY" \
- -H "OpenAI-Organization: $OPENAI_ORG_ID" \
- -d "$json")
- echo $gpt | jq -r '.choices[0].message.content'
-}
-
-################################################################################
-# A straight forward request to the OpenAI GPT-3 model.
-# Takes a single string argument and returns a simple response.
-# hey_openai "What is the best way to open and interate through a file in Perl?"
-# Arguments:
-# Text prompt
-# Output:
-# Writes to stdout
-################################################################################
-hey_openai() {
- prompt="$1"
- local gpt=$(curl https://api.openai.com/v1/chat/completions -s \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer $OPENAI_KEY" \
- -H "OpenAI-Organization: $OPENAI_ORG_ID" \
- -d "{
- \"model\": \"gpt-3.5-turbo\",
- \"messages\": [{\"role\": \"user\", \"content\": \"$prompt\"}],
- \"temperature\": 0.7
- }")
- echo $gpt | jq -r '.choices[0].message.content'
-}
-
append_to_masterlist() {
ml=~/Documents/Notes/todo/masterlist.txt
echo "$1" >> "$ml"
@@ -412,8 +353,6 @@ 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