aboutsummaryrefslogtreecommitdiff
path: root/.kshrc
blob: acf43f98e5509169be8ba5177d70b572e8f1121e (plain) (blame)
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
#
# .kshrc - ksh - Korn shell startup file
#
# See also ksh(1)

# Set vi mode
set -o vi

# If helpers exist
_exists() {
  type $1 > /dev/null 2>&1
}

# Don't let \^{}d logout
set -o ignoreeof

# Export all
set -o allexport

# Setup history
HISTFILE=$HOME/.ksh_history
HISTSIZE=10000
HISTCONTROL=ignoredups:ignorespace:erasedups

# Some useful aliases

# If btop is installed then alias top to btop
_exists btop && alias top='/usr/local/bin/btop'

# If bat exists then alias cat to bat
_exists bat && alias cat='bat --paging=never'

# Use colorls if it's installed, plain old ls otherwise
_exists colorls && alias ls='colorls -G'

alias config='/usr/local/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'

# Only add these aliases if running -current
alias pkg_add='doas pkg_add -Dsnap '
alias pkg_info='doas pkg_info -Dsnap '

# Simple, lightweight git prompt for oksh: if inside a git repo, adds the
# branch name to PS1.
__get_current_git_branch_name() {
	branch_name="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" && \
		[ -n "$branch_name" ] && \
		echo -en " $branch_name"
}

# Set prompt: ``username@hostname directory $ ''
PS1="\[\e[1;32m\]\u@\h \[\e[1;34m\]\w\[\e[0m\] \[\e[1;31m\]\$(__get_current_git_branch_name)\[\e[0m\] $ "

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

# Pager
if _exists less; then
       PAGER=less
       LESSHISTFILE=-
       # -I  ignore case
       # -R  colored output
       # -X  don't clear on exit
       # -Ps string prompt
       # LESS='-IRXPs %lt-%lb (%Pt-%Pb \%) ░ %bt-%bbb ░ %f ░▒▓'
       LESS='-IRX'
       export PAGER LESSHISTFILE LESS
fi

# Coloured man pages
man() {
    sh -c "man '$@' | col -bx | bat -l man"
}

# Search path for cd(1)
CDPATH=:$HOME

# Always add below to allow gpg-agent to work correctly
GPG_TTY=$(tty)

# Enable the use of ssh-agent
if [ ! -f "$XDG_RUNTIME_DIR/ssh-agent.env" ]; then
    pkill -f ssh-agent
fi
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
	. "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi

# Completions

# Display possible interfaces on this machine for ifconfig
set -A complete_ifconfig_1 -- $(ifconfig | grep ^[a-z] | cut -d: -f1)

# Remote access
_SSH_HOSTS=$(awk '/^host/{ print $2 }' ~/.ssh/config)
set -A complete_ssh  -- $_SSH_HOSTS

# Git completion
set -A complete_git -- \
	$(git --list-cmds=main) \
	$(git config --get-regexp ^alias\. | awk -F '[\. ]' '{ print $2 }')

# Dot file Git completion
set -A complete_config  -- add commit diff push status

# OpenBSD rc scripts and rc commands
set -A complete_rcctl_1 -- disable enable get ls order set restart start stop
set -A complete_rcctl_2 -- $(rcctl ls all)