forked from CLOUDWERX-DEV/linux-quick-cheats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·202 lines (177 loc) · 5.6 KB
/
install.sh
File metadata and controls
executable file
·202 lines (177 loc) · 5.6 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
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print with color
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_info() {
echo -e "${BLUE}$1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
# Create necessary directories
print_info "Creating directories..."
mkdir -p ~/bin ~/.cheatsheets
# Create the enhanced cheats script
print_info "Creating cheats script..."
cat > ~/bin/cheats << 'EOF'
#!/bin/bash
CHEATS_DEFAULT_FILE="$HOME/.cheatsheet.txt"
CHEATS_DIR="$HOME/.cheatsheets"
HIGHLIGHT_COLOR=${CHEATS_HIGHLIGHT_COLOR:-"1;33"}
# Debug mode
[[ -n "$CHEATS_DEBUG" ]] && set -x
help() {
echo "Usage: cheats [OPTIONS] [SEARCH_TERM]"
echo
echo "Options:"
echo " -h, --help Show this help message"
echo " -c, --categories List all categories"
echo " -l, --list List all available cheatsheets"
echo " -f FILE Use specific cheatsheet file"
echo " -C NUM Show NUM lines of context"
echo " --export Export current cheatsheet"
echo " --import FILE Import cheatsheet from FILE"
echo " -r, --regex PATTERN Search using regex pattern"
echo
echo "Examples:"
echo " cheats docker Search for docker commands"
echo " cheats -f git.txt Show git-specific cheatsheet"
echo " cheats -C 2 nginx Show nginx entries with 2 lines of context"
}
# Handle different commands
case "$1" in
-h|--help)
help
exit 0
;;
-c|--categories)
grep "^# " "$CHEATS_DEFAULT_FILE"
exit 0
;;
-l|--list)
ls -1 "$CHEATS_DIR"
exit 0
;;
-f)
if [ -f "$CHEATS_DIR/$2" ]; then
cat "$CHEATS_DIR/$2"
else
echo "Cheatsheet not found: $2"
exit 1
fi
exit 0
;;
--export)
cp "$CHEATS_DEFAULT_FILE" "./cheatsheet_backup_$(date +%Y%m%d).txt"
echo "Cheatsheet exported!"
exit 0
;;
--import)
if [ -f "$2" ]; then
cp "$2" "$CHEATS_DEFAULT_FILE"
echo "Cheatsheet imported!"
else
echo "File not found: $2"
exit 1
fi
exit 0
;;
-r|--regex)
if [ -n "$2" ]; then
grep --color=always -E "$2" "$CHEATS_DEFAULT_FILE"
else
echo "Please provide a regex pattern"
exit 1
fi
exit 0
;;
-C)
if [ -n "$3" ]; then
grep --color=always -A "$2" -B "$2" "$3" "$CHEATS_DEFAULT_FILE"
else
echo "Please provide a search term"
exit 1
fi
exit 0
;;
"")
cat "$CHEATS_DEFAULT_FILE"
;;
*)
grep -i --color=always "$1" "$CHEATS_DEFAULT_FILE"
;;
esac
EOF
# Make script executable
chmod +x ~/bin/cheats
# Create initial cheatsheet with some useful commands
print_info "Creating initial cheatsheet..."
cat > ~/.cheatsheet.txt << 'EOF'
# Git Commands
git add . && git commit -m "message" # Stage and commit all changes
git push origin main # Push to main branch
git pull # Pull latest changes
git checkout -b branch-name # Create and switch to new branch
git stash # Stash changes
git stash pop # Apply stashed changes
# Python/UV Commands
uv venv .venv # Create virtual environment
source .venv/bin/activate # Activate virtual environment
pip install -r requirements.txt # Install requirements
python -m pytest # Run tests
uvicorn main:app --reload # Run FastAPI server
# Docker Commands
docker ps -a # List all containers
docker images # List all images
docker-compose up -d # Start services in background
docker system prune -af # Clean all unused resources
docker logs container_name # View container logs
# Linux Shell
ls -la # List all files with details
chmod +x filename # Make file executable
grep -r "text" . # Recursive search
find . -name "*.py" # Find Python files
tar -xvzf file.tar.gz # Extract tar.gz file
df -h # Show disk usage
free -h # Show memory usage
EOF
# Create example category-specific cheatsheets
print_info "Creating category-specific cheatsheets..."
mkdir -p ~/.cheatsheets
cp ~/.cheatsheet.txt ~/.cheatsheets/default.txt
# Add to PATH if not already there
if [[ ":$PATH:" != *":$HOME/bin:"* ]]; then
print_info "Adding ~/bin to PATH..."
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
# Add useful aliases
echo 'alias cheat="cheats"' >> ~/.bashrc
echo 'alias cht="cheats"' >> ~/.bashrc
# Add color customization
echo 'export CHEATS_HIGHLIGHT_COLOR="1;32"' >> ~/.bashrc
fi
# Source bashrc to apply changes
print_info "Source bashrc to apply changes..."
echo source ~/.bashrc
# Final success message
print_success "
Installation complete!
Quick Start:
- Type 'cheats' to see your cheatsheet
- 'cheats search_term' to search
- 'cheats -h' for help
Your cheatsheet is located at: ~/.cheatsheet.txt
Edit this file to add your own commands!
"
# Check if installation was successful
if command -v cheats >/dev/null 2>&1; then
print_success "✓ Installation successful!"
else
print_error "× Something went wrong. Please check the error messages above."
exit 1
fi