~torresjrjr/fetch

ref: 5d20b4a9ac4868f8b56270f0c654932d274cc79f fetch/fetch -rwxr-xr-x 1.9 KiB
5d20b4a9Byron Torres Revert 015c94b "Use ps formatting to simplify..." 10 months ago
                                                                                
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
#!/bin/sh
# A fetch for MSYS2 on Windows.
# @torresjrjr <b@torresjrjr.com>


## Main

main() {
	config
	formatters
	graphic
	reposition
	status
	echo
}


## Graphic

graphic() {
	env printf "$c6%s\n" \
		'      ~       ' \
		'     .-.      ' \
		'    /`v`\     ' \
		'   (/   \)    ' \
		'====="="===<  ' \
		'     |_|      '
}


## Status

status() {
	padding; _title  "${c5}%s@%s ${c3}%s\n"
	padding; _os     "${c6}os      ${c0}%s\n"
	padding; _kernel "${c6}kernel  ${c0}%s\n"
	padding; _shell  "${c6}shell   ${c0}%s\n"
	padding; _sshd   "${c6}sshd    ${c0}%s\n"
	padding; _tmux   "${c6}tmux    ${c0}%s\n"
#	padding; _palette
}


## Statuslines

_title() {
	printf "$1"  "$(whoami)" "$(uname -n)" "$(date -R)"
}
_os() {
	printf "$1"  "$(uname -o)"
}
_kernel() {
	printf "$1"  "$(uname -sr)"
}
_shell() {
	printf "$1"  "$(readlink /proc/$PPID/exe)"
}
_sshd() {
	pids=$(ps ax | awk '!/awk/ && /sshd/ {printf $1 "   "}')
	printf "$1"  "${pids:---}"
}
_tmux() {
	ps ax | grep -v 'grep' | grep -q 'tmux' && tmux_sessions=$(
		tmux ls -F "#{session_created} #{?session_attached,$ul,}#S:#{session_windows}$c0" \
		| sort | awk '{printf $2 "   "}' | xargs -0 printf
	)
	printf "$1"  "${tmux_sessions:---}"
}
_palette() {
	printf "$rv$c1  $c2  $c3  $c4  $c5  $c6  $c0\n"
}


## Config

config() {
	config="${XDG_CONFIG_HOME:-$HOME/.config}/fetch/config.sh"
	[ -f "$config" ] && . "$config"

	graphic_y=$(graphic | wc -l)  # height
	graphic_x=$(graphic | wc -L)  # width
}


## Formatters

formatters() {
	c0='\x1b[0m'    # normal

	c1='\x1b[1;31m' # bold red
	c2='\x1b[1;32m' # bold green
	c3='\x1b[1;33m' # bold yellow
	c4='\x1b[1;34m' # bold blue
	c5='\x1b[1;35m' # bold magenta
	c6='\x1b[1;36m' # bold cyan
	c7='\x1b[1;37m' # bold white

	ul='\x1b[4m'    # underline
	rv='\x1b[7m'    # reverse video
}


## Cursor util

reposition() { printf '\e[%sA\r'  "$graphic_y" ;}
padding()    { printf '\e[%sC'    "$graphic_x" ;}


## Run

main