aboutsummaryrefslogtreecommitdiff
path: root/.bashrc
blob: c7531721b7820db86efe5fa261a0cdd27bc091c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

command_exists() {
  command -v "$1" >/dev/null 2>&1
}

if [[ $- == *i* ]] && [[ -f "/usr/share/blesh/ble.sh" ]]; then
  source /usr/share/blesh/ble.sh --noattach
fi

export PATH="$PATH:/home/umberto/.cargo/bin:$ANDROID_HOME/emulator:/home/umberto/go/bin"
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
export DPREFIX=/mnt/drive_d/.dprefix
export EDITOR=nvim
export HISTSIZE=10000
export HISTFILESIZE=10000
export BAT_THEME=rose-pine

# export TERM=xterm-256color

YELLOW="\[$(tput setaf 3)\]"
GREEN="\[$(tput setaf 2)\]"
RED="\[$(tput setaf 1)\]"
BLUE="\[$(tput setaf 4)\]"
RESET="\[$(tput sgr0)\]"

dockersize() {
  docker manifest inspect -v "$1" |
    jq -c 'if type == "array" then .[] else . end' |
    jq -r '[ ( .Descriptor.platform | [ .os, .architecture, .variant, ."os.version" ] | del(..|nulls) | join("/") ), ( [ ( .OCIManifest // .SchemaV2Manifest ).layers[].size ] | add ) ] | join(" ")' |
    numfmt --to iec --format '%.2f' --field 2 |
    sort | column -t ;
}

avg_time() {
  #
  # usage: avg_time n command ...
  #
  n=$1; shift
  (($# > 0)) || return                   # bail if no command given
  for ((i = 0; i < n; i++)); do
    { time -p "$@" &>/dev/null; } 2>&1 # ignore the output of the command
      # but collect time's output in stdout
    done | awk '
    /real/ { real = real + $2; nr++ }
    /user/ { user = user + $2; nu++ }
    /sys/  { sys  = sys  + $2; ns++}
    END    {
    if (nr>0) printf("real %f\n", real/nr);
    if (nu>0) printf("user %f\n", user/nu);
        if (ns>0) printf("sys %f\n",  sys/ns)
        }'
}

key()
{
  pidof ssh-agent
  if [[ $? -eq 1 ]] || [[ -z "${SSH_AGENT_PID}" ]]; then
    killall ssh-agent ; eval $(ssh-agent -t 4h) && ssh-add ~/.ssh/id_ed25519
  elif [[ "$1" == "--force" ]] || [ "$1" == "-f" ]; then
    killall ssh-agent ; eval $(ssh-agent -t 4h) && ssh-add ~/.ssh/id_ed25519
  fi
}

starter() {
  newsboat
  sudo pacman -Syu
  setxkbmap hu -option caps:escape
  read -p "Update AUR packages? [Y/n]: " aur_pkgs
  if [[ -z "$aur_pkgs" ]] || [[ "$aur_pkgs" == "Y" ]] || [[ "$aur_pkgs" == "y" ]]; then
    tmux new-session 'aur ; bash'
  fi
}

alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias btm='btm --enable_gpu'
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias eza='eza --icons'
alias tree='eza --tree'
alias ncdu='ncdu -t4'
alias fvim='nvim $(fzf)'
alias c='clear'
alias d='cd /mnt/drive_d/'
alias q='cd /mnt/drive_d/Quest/'
alias pac='sudo pacman'
alias pacs="pacman -Slq | fzf --preview 'pacman -Sii {}' --layout=reverse --bind 'enter:execute(pacman -Sii {} | less)'"
alias paci="pacman -Qq | fzf --preview 'pacman -Qi {}' --layout=reverse --bind 'enter:execute(pacman -Qi {} | less)'"
alias orphans='pacman -Qdtq && pacman -Qdtq | pac -Rns -'
alias cls='c && eza'
alias cla='c && eza -a'
alias lazygit='key && lazygit'
alias diff='diff --color -up'
alias emu='emulator -avd Pixel_3a_API_34_extension_level_7_x86_64 -accel on -gpu host -memory 3072'
alias proton='STEAM_COMPAT_DATA_PATH=$HOME/proton/compatdata/ STEAM_COMPAT_CLIENT_INSTALL_PATH=/ ~/proton/GE-Proton9-11/proton waitforexitandrun'

source ~/.git-completion.bash

parse_git_bg() {
  if [[ $(git status -s 2> /dev/null) ]]; then
    tput setaf 160
  else
    tput setaf 34
  fi
}

PS1="╭─${YELLOW}"
PS1+="\u${GREEN}"
PS1+="@${RED}"
PS1+="\h${BLUE} "
PS1+="\W${RESET}"
PS1+="\$(git branch 2> /dev/null | grep '^*' | colrm 1 2 | xargs -I BRANCH echo -n \"" 
PS1+="\$(parse_git_bg) "
PS1+=" (BRANCH) " 
PS1+="${RESET}\")\n" 
PS1+="╰─" 
PS1+="\\$ " 
PS1+="${RESET}"
export PS1

# pnpm
export PNPM_HOME="/home/umberto/.local/share/pnpm"
case ":$PATH:" in
  *":$PNPM_HOME:"*) ;;
  *) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end

export FZF_DEFAULT_OPTS="
	--color=fg:#908caa,bg:#191724,hl:#ebbcba
	--color=fg+:#e0def4,bg+:#26233a,hl+:#ebbcba
	--color=border:#403d52,header:#31748f,gutter:#191724
	--color=spinner:#f6c177,info:#9ccfd8,separator:#403d52
	--color=pointer:#c4a7e7,marker:#eb6f92,prompt:#908caa"

command_exists fetcha && fetcha

[[ ${BLE_VERSION-} ]] && ble-attach