summaryrefslogtreecommitdiff
path: root/.bashrc
blob: 317bdb6de6b921bcbed7738fd8a9deb722c53a8d (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
# ~/.bashrc

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

export PAGER=less
export EDITOR=vim
export MANPAGER='vim +MANPAGER --not-a-term -'
export HISTIGNORE='sudo id:uname:date:exit:df:ll:ls:ps:pwd:tc:top:history'
export HISTCONTROL=ignoreboth:erasedups  # no start space and duplicate entries
export HISTSIZE=100000                   # big big history
export HISTFILESIZE=100000               # big big history
shopt -s histappend                      # append to history, don't overwrite it
shopt -s globstar
shopt -s dotglob

stty -ixon # disable Ctrl-S

# Save and reload the history after each command finishes
#export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

# export GNUTERM='sixelgd enhanced truecolor font "arial,9"'
#
OS=${OS:-$(~/bin/os)}

# Support different operating system environments
case $OS in
(arch|alpine|fedora-asahi-remix)
	alias ls='ls --color=auto -v' ll='ls -AlFhv'
	[ "$OS" = arch ] || trap 'printf "\e]2;%s\a" "$TERM_TAG ${BASH_COMMAND%ps1}"' DEBUG
	;;
(Darwin)
	alias ibrew='arch -x86_64 /usr/local/bin/brew'
	alias ls='ls -GF' ll='ls -AlGFhv'
	alias ldd='otool -L'
	trap 'printf "\e]2;%s\a" "$TERM_TAG ${BASH_COMMAND%update_terminal_cwd}"' DEBUG
	;;
(termux)
	PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin
	type eza >/dev/null && alias ls='eza' ll='eza -lao --no-user --no-permissions' ||
		alias ls='ls --color=auto -v' ll='ls -AlFhv'
	;;
esac

p() {  [ -f "$1" -a ! -x "$1" ] && less "$1" || "$@" 2>&1 | less; }
export -f p

[ "$OS" = alpine ] && export MANPAGER='vim +MANPAGER --not-a-term'

export LESS=iXFRx4

#export BACKUP=bip:/home/backup/marc@$(hostname -s)

# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'

alias apk='doas apk'
alias dotfiles='git --git-dir=$HOME/dotfiles --work-tree=$HOME'
alias dy='YAEGI_AST_DOT=1 YAEGI_CFG_DOT=1 ./yaegi'
alias f2fa='2fa -list | fzf | xargs 2fa -clip'
alias fd='find . -iname'
alias gdt='dlv test -- -test.v -test.run'
alias gob='go build'
alias god='p go doc'
alias goh='p go help'
alias gol='GO111MODULE=off go'
alias grep='grep -i --color'
alias gtb='go test -v -cpuprofile cpu.out -memprofile mem.out -benchmem -bench'
alias gtr='go test -v -run'
alias more='less'
alias oman='MANPAGER= man'
alias rg='rg --smart-case'
alias rot13='tr A-Za-z N-ZA-Mn-za-m'
alias vi='vim'
alias view='vim -R'
alias ww='vi ~/Wiki/home_page.md'
alias y='rlwrap -pblue yaegi'

# yaegi debug
export YAEGI_DOT_CMD='dotty -'
export YAEGI_UNSAFE=1
export YAEGI_UNRESTRICTED=1
export YAEGI_SYSCALL=1

sshs() { ssh -t "$@" -- screen -d -R; }

man() {
	local width=''
	[ $(tput cols) -gt 88 ] && width='MANWIDTH=88'
	env $width man "$@"
}

meteo() {
    local request="wttr.in/${1-Toulouse}?F&T"
    [ "$(tput cols)" -lt 125 ] && request+='&n'
    curl -H "Accept-Language: fr" --compressed "$request"
}

eval "$(fzf --bash)" >/dev/null

# Handle missing commands, unless already provided.
type -t command_not_found_handle >/dev/null || command_not_found_handle() {
	case $OS in
	(alpine) pkgs=$(apk list -Pq "cmd:$1" | awk '{print $2}') ;;
	(arch)   pkgs=$(pkgfile -b "$1") ;;
	(Darwin) pkgs=$(brew which-formula "$1") ;;
	esac
	echo "$1: command not found${pkgs:+. Present in: $pkgs}" >&2
}

# Display git status in prompt
. ~/.bash-powerline.sh