-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc.readme
More file actions
executable file
·283 lines (199 loc) · 10.3 KB
/
bashrc.readme
File metadata and controls
executable file
·283 lines (199 loc) · 10.3 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# Enhanced Bashrc Documentation
This document provides an overview of the enhancements made to your bashrc file, explaining the new features, improvements, and how to use them effectively.
## Overview of Enhancements
The enhanced bashrc file (version 3.0.0) includes significant improvements in the following areas:
1. **Performance Optimization**
- Lazy loading of development environments
- Improved caching mechanisms
- Reduced subshell usage
- Optimized prompt rendering
2. **Security Enhancements**
- Comprehensive file permission checks
- SSH key security verification
- File integrity monitoring
- Security update notifications
- Secure file deletion
3. **History Management**
- Directory context with history entries
- Improved history synchronization
- Better filtering of sensitive commands
- Enhanced history search capabilities
4. **Prompt Improvements**
- Command execution timing
- Git status with stash and upstream information
- Terminal width-aware prompt sizing
- Security status indicators
5. **Navigation and Productivity**
- Enhanced directory jumping with fuzzy matching
- Improved directory stack manipulation
- Automatic directory listing after cd
- Bookmark management
6. **Modular System**
- Enhanced module management
- Improved loading of configuration files
- Better organization of functions and aliases
7. **Utility Functions**
- System monitoring tools
- File management utilities
- Network information tools
- Development helpers
## Installation
To use the enhanced bashrc:
1. Back up your current bashrc:
```bash
cp ~/.bashrc ~/.bashrc.backup
```
2. Replace your current bashrc with the enhanced version:
```bash
cp /path/to/enhanced_bashrc.sh ~/.bashrc
```
3. Source the new bashrc:
```bash
source ~/.bashrc
```
## Configuration Options
The enhanced bashrc includes many configuration options that can be customized by setting environment variables before sourcing the bashrc or by editing the CONFIG array in the file:
```bash
# Example: Disable lazy loading in your ~/.bashrc.precustom
export U_LAZY_LOAD=0
```
Key configuration options include:
- `DEBUG`: Enable debug mode (0=off, 1=on)
- `LAZY_LOAD`: Lazy load heavy components (0=off, 1=on)
- `CACHE_PROMPT`: Cache prompt components (0=off, 1=on)
- `SECURE_UPDATES`: Check for security updates (0=off, 1=on)
- `HIST_CONTEXT`: Store directory context with history (0=off, 1=on)
- `COMMAND_TIMING`: Show execution time for commands (0=off, 1=on)
- `SMART_PROMPT`: Adjust prompt based on terminal width (0=off, 1=on)
- `ENHANCED_CD`: Enhanced directory navigation (0=off, 1=on)
## New Features
### Enhanced Prompt
The prompt now includes:
- Command execution time
- Git branch, status, stash count, and upstream status
- Security indicators for SSH and sudo sessions
- Exit status of previous command
- Job count indicator
- Adaptive sizing based on terminal width
### Directory Navigation
Enhanced `cd` command with:
- Directory stack manipulation (`cd --` to show stack, `cd -N` to go to Nth directory)
- Auto-listing of directory contents after changing directories
- Shorthand for common operations (`cd -` for previous, `cd +dir` to push to stack)
### Bookmarks with Fuzzy Matching
The `j` command allows you to bookmark and jump to directories:
- `j -a` to add current directory to bookmarks
- `j -l` to list bookmarks
- `j -r N` to remove bookmark number N
- `j N` to jump to bookmark number N
- `j pattern` to fuzzy search bookmarks
### Security Tools
New security features include:
- `checksec file` to check file security properties
- `securerm file` to securely delete files
- `check_file_integrity file` to verify file integrity
- `update_file_integrity dir` to update integrity database
- Automatic security update notifications
### System Monitoring
New monitoring tools:
- `sysmon [delay] [count]` to monitor system resources
- `findlarge [size] [count]` to find large files
- `findempty` to find empty directories
- `check_security_updates` to check for security updates
### Development Tools
Improved development environment support:
- Lazy loading of Pyenv, NVM, RVM, and Cargo
- Enhanced Git aliases and functions
- Simple HTTP server with `serve [port]`
- Password generation with `genpass [length]`
## Performance Improvements
The enhanced bashrc includes several performance optimizations:
1. **Lazy Loading**: Development environments are only loaded when needed
2. **Prompt Caching**: Git status information is cached to reduce command execution
3. **Completion Optimization**: Programmable completion is loaded on first Tab press
4. **Path Sanitization**: PATH is cleaned of duplicates and invalid entries
5. **Conditional Execution**: Heavy operations are only performed when necessary
## Customization
The bashrc is designed to be easily customizable:
- `~/.bashrc.precustom`: Loaded at the beginning for early customization
- `~/.bashrc.postcustom`: Loaded at the end for overriding defaults
- `~/.bash_aliases`: For custom aliases
- `~/.bash_functions`: For custom functions
- `~/.bash_aliases.d/`: Directory for organizing aliases by category
- `~/.bash_functions.d/`: Directory for organizing functions by category
- `~/.bash_modules.d/`: Directory for modular extensions
## Module System
The enhanced bashrc includes a module system for organizing and loading extensions:
- `module_enable name` to enable a module
- `module_disable name` to disable a module
- `module_list` to list available modules
Modules are stored in `~/.bash_modules.d/` as shell scripts.
## Help and Documentation
Type `help-sentinel` to see a list of available commands and features.
## Compatibility
The enhanced bashrc is designed to work across different Linux distributions and versions of Bash. It includes detection and adaptation for:
- Different package managers (apt, dnf, yum, pacman)
- Different terminal capabilities
- Presence or absence of various utilities
## Troubleshooting
If you encounter issues:
1. Enable debug mode: `export U_DEBUG=1` before sourcing
2. Check the profile output: `export BASHRC_PROFILE=1` before sourcing
3. Disable features incrementally to isolate problems
4. Check for error messages in the console output
# Enhancement Opportunities for Bashrc
Based on analysis of the current bashrc file and research on modern bash best practices, I've identified the following enhancement opportunities:
## 1. Performance Optimizations
- **Lazy Loading**: Implement more aggressive lazy loading for heavy components like completion systems and development environments
- **Caching Mechanism**: Enhance the caching system for prompt components and frequently used commands
- **Process Substitution**: Add examples and utilities using process substitution for more efficient I/O operations
- **Mapfile Usage**: Replace traditional line-by-line file reading with mapfile/readarray for better performance
- **Reduced Subshell Usage**: Optimize functions to minimize subshell creation where possible
## 2. Security Enhancements
- **SSH Hardening**: Add configuration for SSH key management and connection hardening
- **File Integrity Monitoring**: Add simple file integrity checking for critical system files
- **Credential Management**: Improve handling of credentials and sensitive information
- **Audit Logging**: Add basic audit logging for critical commands and actions
- **Automatic Security Updates**: Add functionality to check for and notify about security updates
## 3. History Management
- **Enhanced History Control**: Improve history management with better filtering and search capabilities
- **History Synchronization**: Add functionality to synchronize history between multiple sessions
- **Command Timing**: Record and display execution time for commands in history
- **Context-Aware History**: Store directory context with history entries for better organization
## 4. Prompt Improvements
- **Information Density**: Add more useful information to the prompt without sacrificing performance
- **Git Integration**: Enhance git status information with more details (stashes, upstream status)
- **Command Duration**: Add execution time for previous command to prompt
- **Dynamic Prompt Sizing**: Adjust prompt based on terminal width
## 5. Utility Functions
- **Enhanced Navigation**: Add more advanced directory navigation functions
- **Project Management**: Add project-specific environment management
- **Development Workflow**: Add functions for common development tasks
- **System Monitoring**: Add simple system monitoring capabilities
## 6. Modern Bash Features
- **Associative Arrays**: Add examples and utilities using associative arrays
- **Parameter Expansion**: Leverage advanced parameter expansion techniques
- **Brace Expansion**: Add examples and utilities using brace expansion
- **Improved Completion**: Enhance completion with custom completion functions
## 7. Documentation and Organization
- **Section Headers**: Add clear section headers for better organization
- **Function Documentation**: Improve documentation for functions with usage examples
- **Configuration Documentation**: Add documentation for configuration options
- **Version Control**: Add version control information and update mechanism
## 8. Environment Detection and Adaptation
- **Terminal Capability Detection**: Better detection and adaptation to terminal capabilities
- **OS/Distribution Detection**: Improve OS and distribution detection for better compatibility
- **Hardware Detection**: Add detection for hardware capabilities (CPU cores, memory)
- **Network Environment**: Detect and adapt to different network environments
## 9. Integration with Modern Tools
- **Container Support**: Add support for container environments
- **Cloud Integration**: Add functions for interacting with cloud services
- **Modern CLI Tools**: Add integration with modern CLI tools (fzf, ripgrep, bat, etc.)
- **Development Environments**: Better integration with modern development environments
## 10. User Experience
- **Startup Time**: Optimize startup time with better profiling and optimization
- **Error Handling**: Improve error handling and reporting
- **User Feedback**: Add better user feedback for long-running operations
- **Customization**: Make it easier for users to customize their environment
## Acknowledgments
This enhanced bashrc builds upon the original work by Jason Thistlethwaite (2013) with significant enhancements to improve security, performance, and usability.