-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.fish
181 lines (157 loc) · 4.74 KB
/
config.fish
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Firendly Interactive Shell configure
# Path of this file ~/.config/fish/config.fish
# @zomby7e
# varribles for this file
set need_install # packages that need to be installed
set install_hint 1 # 1 on, 0 off
set translate_manual_to "zh_TW" # First language for man
# Editor config
if command -v kate >/dev/null
set -x VISUAL "kate"
else
set need_install "$need_install""kate "
end
if command -v vim >/dev/null
set -x EDITOR "vim"
alias vi vim
alias vimfish "vim ~/.config/fish/config.fish"
else
set need_install "$need_install""vim "
end
# Command line tools
# Better cat
if command -v bat >/dev/null
alias cat bat
else
set need_install "$need_install""bat "
end
# Better less
if command -v source-highlight >/dev/null
set src_hl_path (which src-hilite-lesspipe.sh)
export LESSOPEN="| $src_hl_path %s"
export LESS=' -R '
else
set need_install "$need_install""source-highlight "
end
# Fish config
function fish_greeting
printf "Fish opened @ \033[0;92m%s \033[0m\n" (date "+%H:%M %m/%d/%Y")
if string length --quiet $need_install
and test "$install_hint" = "1"
printf "There are some packages missing, install them for better experience:\n%s\n" $need_install
printf "Edit your fish config file to disable this hint, Enter `vimfish`.\n"
end
set current_shell (basename $SHELL)
if not test "$current_shell" = "fish"
printf "Your default shell is not fish, if you need enter `ineedfish`\n"
alias ineedfish 'chsh -s (which fish)'
end
end
# Web search engines
function google
if test (count $argv) -eq 0
echo "Usage: google <search term>"
return 1
end
set -l query (string join " " $argv | string replace " " "%20")
set -l url "https://www.google.com/search?q=$query"
xdg-open $url
end
# YouTube
function youtube
if test (count $argv) -eq 0
echo "Usage: youtube <search term>"
return 1
end
set -l query (string join " " $argv | string replace " " "%20")
set -l url "https://www.youtube.com/results?search_query=$query"
xdg-open $url
end
# Wikipedia
function wiki
if test (count $argv) -eq 0
echo "Usage: wiki <search term>"
return 1
end
set -l query (string join " " $argv | string replace " " "%20")
set -l url "https://en.wikipedia.org/wiki/Special:Search?search=$query"
xdg-open $url
end
# Get basic system information
function basicinfo
printf "User@Host: %s@%s\n" $USER (hostname)
# Get distro name through the file.
if test -f /etc/os-release
set -l distro_name (grep '^NAME=' /etc/os-release | cut -d'=' -f2 | tr -d '"')
set -l distro_version (grep '^VERSION=' /etc/os-release | cut -d'=' -f2 | tr -d '"')
echo "Distro: $distro_name $distro_version"
else
echo "Unable to retrieve distribution information."
end
printf "Kernel Info: %s\n" (uname -sr)
printf "Platform: %s\n" (uname -m)
set uptime (uptime -p)
set uptime (string replace "up " "" $uptime)
printf "Uptime: %s\n" $uptime
printf "Shell: %s\n" (basename $SHELL)
set cpu_name (cat /proc/cpuinfo | grep "model name" | uniq | sed "s/.*: //")
# Get memory info
switch (uname -s)
case 'Linux'
set mem_info (free -h | grep Mem)
set total_mem (echo $mem_info | awk '{print $2}')
set used_mem (echo $mem_info | awk '{print $3}')
echo "Memory: $used_mem / $total_mem"
case 'FreeBSD'
case 'NetBSD'
case 'OpenBSD'
case 'DragonFly'
set -l mem_info (vmstat -H)
set -l total_mem (echo $mem_info | awk '{print $4}')
set -l used_mem (echo $mem_info | awk '{print $3}')
echo "Memory: $used_mem / $total_mem"
case '*'
:
end
#TODO: GPU modal nema, SWAP info, Disk usage
end
# Set Network proxy
function setproxy
set -l host
set -l port
if test (count $argv) -eq 1
set -l proxy (string split ":" $argv[1])
set host $proxy[1]
set port $proxy[2]
else
echo "Host name / IP address:"
read host
echo "Port:"
read port
end
if test -z "$host" -o -z "$port"
echo "Invalid input"
return 1
end
set -gx http_proxy "http://$host:$port"
set -gx https_proxy "http://$host:$port"
set -gx ftp_proxy "http://$host:$port"
set -gx no_proxy "localhost,127.0.0.1"
echo "Network proxy has been set to: $host:$port"
end
# Unset proxy
function unsetproxy
set -e http_proxy
set -e https_proxy
set -e ftp_proxy
set -e no_proxy
echo "Network proxy has been unset"
end
# Translated manual
function tman
if man -M /usr/share/man/$translate_manual_to "$argv[1]" > /dev/null 2>&1
man -M /usr/share/man/$translate_manual_to "$argv"
else
man "$argv"
end
end