summaryrefslogtreecommitdiff
path: root/.yashrc
blob: 3f4fe0594f82fca407cb95d7748983919f59a945 (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
_ps1_prompt() {
	cmd_status=$?
	cmd_duration=$((CMD_DURATION / 1000))
	CMD_DURATION=0
	is_git=$(git rev-parse --is-inside-work-tree 2>/dev/null)

	prompt="\n\\foc."
	if [ "$is_git" ]; then
		prompt="$prompt$(git rev-parse --show-toplevel | awk -F/ '{ print $NF }')"
		git_path=$(git rev-parse --show-prefix)
		git_path="${git_path%/}"
		prompt="$prompt${git_path:+"/$git_path"}"
	elif [ "${PWD#"$HOME"}" != "$PWD" ]; then
		prompt="$prompt~${PWD#"$HOME"}"
	else
		prompt="$prompt$PWD"
	fi
	prompt="$prompt\\fD."

	if [ "$is_git" ]; then
		prompt="$prompt on \\fom. $(git branch --show-current)"

		stat=
		git rev-parse --verify refs/stash >/dev/null 2>&1 && stat="$stat\$"
		status="$(git status --porcelain -b)"
		case "$status" in
			U[UDA]*|AA*|DD*|[DA]U*)  stat="$stat=" ;;
		esac
		case "$status" in
			[MARCDU\ ]D*|D[\ UM]*)   stat="$stat✘" ;;
		esac
		case "$status" in
			R[\ MD]*)                stat="$stat»" ;;
		esac
		case "$status" in
			[\ MARC]M*)              stat="$stat!" ;;
		esac
		case "$status" in
			A[\ MDAU]*|M[\ MD]*|UA*) stat="$stat+" ;;
		esac
		case "$status" in
			'??'*)                   stat="$stat?" ;;
		esac
		case "$status" in
			'## '*ahead*behind*) stat="$stat⇕" ;;
			'## '*ahead*) stat="$stat⇡" ;;
			'## '*behind*) stat="$stat⇣" ;;
		esac
		prompt="$prompt${stat:+"\\for. [$stat]"}"
	fi

	if [ "$cmd_duration" -gt 1 ]; then
		prompt="$prompt took\\foy."

		secs=$((cmd_duration % 60))
		mins=$((cmd_duration / 60 % 60))
		hours=$((cmd_duration / 3600))

		[ "$hours" -gt 0 ] && prompt="$prompt ${hours}h"
		[ "$mins" -gt 0 ] && prompt="$prompt ${mins}m"
		[ "$secs" -gt 0 ] && prompt="$prompt ${secs}s"
	fi
	prompt="$prompt\n"

	n_jobs="$(jobs 2>/dev/null | wc -l)"
	if [ "$n_jobs" -gt 0 ]; then
		[ "$n_jobs" -le 1 ] && n_jobs=
		prompt="$prompt\\fob.✦ ${n_jobs:+"$n_jobs "}"
	fi
	case "$cmd_status" in
		0) printf '%s\\fg.❯ \\fD.' "$prompt" ;;
		*) printf '%s\\fr.❯ \\fD.' "$prompt" ;;
	esac
}

export PS1='$(_ps1_prompt)'

export HISTSIZE=100000
export HISTRMDUP=10

set le-predict

alias cfg='git --git-dir ~/.cfg --work-tree ~'
alias tree='tree -C'