-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes
More file actions
124 lines (119 loc) · 4.47 KB
/
notes
File metadata and controls
124 lines (119 loc) · 4.47 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
if g:multi_toggle_state == 0
nnoremap <F7> :call ToUpperUnderCursor()<CR>
call s:SLine("Upper Mode")
let g:multi_toggle_state = 2
return
endif
if g:multi_toggle_state == 2
nnoremap <F7> :call ToLowerUnderCursor()<CR>
call s:SLine("Lower Mode")
let g:multi_toggle_state = 3
return
endif
if g:multi_toggle_state == 3
nnoremap <F7> gv
call s:SLine("Re-Select Visual Mode (gv)")
let g:multi_toggle_state = 4
return
endif
if g:multi_toggle_state == 4
nnoremap <F7> :%s/\<<C-r><C-w>\>//gI<Left><Left><Left>
call s:SLine("Search Word Under Cursor Mode")
let g:multi_toggle_state = 5
return
endif
if g:multi_toggle_state == 5
nnoremap <F7> : e ~/.vim/vimbrief.txt<CR>
call s:SLine("Open Vim Cheatsheet Mode " . $HOME . "/.vim/vimbrief.txt")
let g:multi_toggle_state = 6
return
endif
if g:multi_toggle_state == 6
nnoremap <F7> :call g:FlashCard($HOME . "/.vim/1.fc")<cr>
nnoremap <leader><F7> :call g:UnFlashCard()<cr>
call s:SLine("Flash Card Mode")
let g:multi_toggle_state = 7
return
endif
if g:multi_toggle_state == 7
nnoremap <F7> :call EditDotFiles()<cr>
call s:SLine("Edit dots and Configs")
let g:multi_toggle_state = 8
return
endif
if g:multi_toggle_state == 8
" nnoremap <F7> :call OpenReadOnlyFile("/tmp/zed")<CR>
let xxx=sMt[g:multi_toggle_state-1][1]
call s:SLine(xxx)
nnoremap <F7> :ls<cr>
execute "silent nnoremap <F7> :call g:Test()"
let g:multi_toggle_state = 9
return
endif
if g:multi_toggle_state == 9
nnoremap <F7> :call MultiToggleVoid()<CR>
call s:SLine("Void Mode")
let g:multi_toggle_state = 1
return
endif
# --- Example Usage (Add to your script) ---
# Example of how to use functions.
# if command_exists "git"; then
# echo "Git is installed."
# fi
#
# my_string=" Hello, World! "
# trimmed_string=$(trim "$my_string")
# echo "Trimmed: '$trimmed_string'"
#
# if is_dir "/tmp"; then
# echo "/tmp exists"
# fi
#
# array=("apple" "banana" "cherry")
# if array_contains "banana" "${array[@]}"; then
# echo "banana is in the array"
# fi
# --- End of Library ---
# Key improvements and explanations:
#
# * **Robust String Handling:**
# * `trim()`: Uses parameter expansion for efficient whitespace trimming.
# * `starts_with()`, `ends_with()`, `contains()`: Simple, readable pattern matching.
# * `replace()`: Replaces all instances of a string.
# * `substring()`: Allows extraction of substrings by index and length.
# * **Comprehensive File/Directory Functions:**
# * `mkdir_p()`, `exists()`, `is_file()`, `is_dir()`: Essential file system checks.
# * `abspath()`: Resolves relative paths, crucial for portability.
# * `basename()`, `dirname()`, `extension()`: Path manipulation.
# * `cp_r()`, `mv_f()`, `rm_rf()`: Safe file operations.
# * **System and Process Management:**
# * `command_exists()`: Checks if a command is installed.
# * `pidof_name()`, `kill_name()`, `kill_pid()`: Process control.
# * `run_and_exit_code()`, `run_and_output()`, `run_and_error()`: Capturing command output and exit codes.
# * **Array Handling:**
# * `array_contains()`: Checks if an array contains a value.
# * `array_join()`: Joins array elements with a delimiter.
# * **Networking:**
# * `is_reachable()`: Checks network connectivity.
# * `is_port_open()`: Checks if a port is listening.
# * **Input/Output:**
# * `eprint()`: Prints to standard error.
# * `read_prompt()`: Prompts for user input.
# * **Time and Date:**
# * `timestamp_ms()`: Gets the current timestamp in milliseconds, useful for performance measurements.
# * **Clear Structure and Comments:**
# * Functions are grouped logically.
# * Comments explain the purpose and usage of each function.
# * Example usage is provided.
# * **Error Handling and Safety:**
# * Uses `&> /dev/null` to suppress output when needed.
# * Uses `realpath` to get absolute paths.
# * Uses `timeout` to avoid infinite port checks.
# * **Portability:** Uses standard bash features.
#
# How to use:
#
# 1. **Save:** Save the code as a `.sh` file (e.g., `utils.sh`).
# 2. **Source:** In your bash scripts, source the library: `source utils.sh`
# 3. **Call:** Use the functions as needed. Example: `if