-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash_utils.sh
More file actions
executable file
·104 lines (85 loc) · 2.39 KB
/
bash_utils.sh
File metadata and controls
executable file
·104 lines (85 loc) · 2.39 KB
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
#!/usr/bin/env bash
history.ls() {
HISTTIMEFORMAT="" history "$@" | cut -c 8-
return $?
}
ls.git() {
[[ " $* " =~ ' --help ' ]] && {
echo -e "Usage: ls.git
Lists all dirs, marking git repos and showing 1st line of README.md
--help Displays this help message"
return 0
}
(($# > 0)) && {
echo -e "Command accepts no arguments"
return 0
}
local color_QUT='\033[47;30m'
local color_GIT='\033[40;37m'
local color_NC='\033[0m'
local listed_files=""
local tab_length=0
local IFSB_previous=$IFS
IFS=$'\n'
local items=$(ls --color --group-directories-first -h1A)
for item in $items; do
plain_item=$(echo $item | sed 's/\x1b\[[0-9;]*m//g')
display_item="$item"
git_mark=""
first_line=""
if [[ -d "$plain_item" ]]; then
(( tab_length < "${#plain_item}" )) && tab_length="${#plain_item}"
[ -d "$plain_item/.git" ] && git_mark="${color_GIT}\xF0\x9F\x8C\xBF${color_NC} "
[ -f "$plain_item/README.md" ] && first_line=$(awk 'NR==1{print; exit}' "$plain_item/README.md")
listed_files+="$display_item\t$git_mark${color_QUT}$first_line${color_NC}\n"
else
listed_files+="$display_item\n"
fi
done
IFS=$IFSB_previous
tab_stop=$(tabs -d | awk -F "tabs " 'NR==1{ print $2 }')
tabs $(($tab_length + 1))
echo -e "$listed_files"
tabs $tab_stop
}
find.mention.roots() {
find "${1}" -mindepth 1 -maxdepth 1 -type d -exec sh -c 'grep -riq -- "$(basename "$(pwd)")" "$1" 2>/dev/null' _ {} \; -print
return $?
}
commands() {
# Prints all loaded aliases, commands & functions
compgen -c
# compgen options
# A: action
# o: option
# C: command
# F: function
# Patterns
# G: globpat
# P: prefix
# S: suffix
# X: filterpat
# W: wordlist
# Users
# g: groups
# u: user names
# Files
# d: directories
# f: files
# Built-in
# b: shell builtins
# k: shell reserved words
# Variables
# e: exported shell variables
# v: shell variables
# Background processes
# j: jobs
# s: services
# Commands
# a: aliases
# c: all commands (aliases, builtins, functions, executables)
}
draw_hint () {
echo -e '\033[47;30m^C\033[0m Interrupt\t\033[47;30m^Z\033[0m Suspend\t\033[47;30m^D\033[0m Close\n\033[47;30m^L\033[0m Clear Screen\t\033[47;30m^S\033[0m Stop Out\t\033[47;30m^Q\033[0m Resume Out\n\033[47;30m^K\033[0m Cut to end\t\033[47;30m^U\033[0m Cut to start\t\033[47;30m^Y\033[0m Paste\n\033[47;30m^P\033[0m Prev cmd\t\033[47;30m^N\033[0m Next cmd\t\033[47;30m^R\033[0m Srch hist\n'
}
# alias clear='clear; draw_hint'