-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
144 lines (118 loc) · 4.42 KB
/
Copy pathinstall.sh
File metadata and controls
144 lines (118 loc) · 4.42 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
#!/usr/bin/env bash
# Installation script for git-ignore extension
# This script installs git-ignore command and shell completions
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="${HOME}/.local/bin"
COMPLETION_DIR_BASH="${HOME}/.local/share/bash-completion/completions"
COMPLETION_DIR_ZSH="${HOME}/.zsh/completions"
# Colours for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
print_info() {
echo -e "${BLUE}ℹ $1${NC}"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
# Check if running from the correct directory
if [[ ! -f "${SCRIPT_DIR}/git-ignore" ]]; then
print_error "git-ignore script not found in current directory"
exit 1
fi
echo "==================================="
echo "Git Ignore Extension Installer"
echo "==================================="
echo
# Create installation directory if it doesn't exist
if [[ ! -d "$INSTALL_DIR" ]]; then
print_info "Creating installation directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
fi
# Install the main script
print_info "Installing git-ignore command..."
cp "${SCRIPT_DIR}/git-ignore" "$INSTALL_DIR/git-ignore"
chmod +x "$INSTALL_DIR/git-ignore"
print_success "Installed git-ignore to $INSTALL_DIR"
# Check if install directory is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
print_warning "$INSTALL_DIR is not in your PATH"
echo
echo "Add the following line to your shell configuration file:"
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo
# Detect shell and suggest the right config file
if [[ -n "$BASH_VERSION" ]]; then
echo "For bash, add to ~/.bashrc or ~/.bash_profile"
elif [[ -n "$ZSH_VERSION" ]]; then
echo "For zsh, add to ~/.zshrc"
fi
fi
# Install bash completion
if [[ -f "${SCRIPT_DIR}/git-ignore-completion.bash" ]]; then
print_info "Installing bash completion..."
# Create bash completion directory if it doesn't exist
mkdir -p "$COMPLETION_DIR_BASH"
# Install completion file
cp "${SCRIPT_DIR}/git-ignore-completion.bash" "$COMPLETION_DIR_BASH/git-ignore"
print_success "Installed bash completion"
# Check if bash completion is sourced
if [[ -n "$BASH_VERSION" ]]; then
if [[ -f ~/.bashrc ]] && ! grep -q "bash-completion/completions" ~/.bashrc; then
print_info "To enable bash completion, add to ~/.bashrc:"
echo " for file in ~/.local/share/bash-completion/completions/*; do"
echo " [ -f \"\$file\" ] && source \"\$file\""
echo " done"
fi
fi
fi
# Install zsh completion
if [[ -f "${SCRIPT_DIR}/git-ignore-completion.zsh" ]]; then
print_info "Installing zsh completion..."
# Create zsh completion directory if it doesn't exist
mkdir -p "$COMPLETION_DIR_ZSH"
# Install completion file with proper naming for zsh
cp "${SCRIPT_DIR}/git-ignore-completion.zsh" "$COMPLETION_DIR_ZSH/_git-ignore"
print_success "Installed zsh completion"
# Check if zsh completion directory is in fpath
if [[ -n "$ZSH_VERSION" ]]; then
print_info "To enable zsh completion, ensure the following in ~/.zshrc:"
echo " fpath=(~/.zsh/completions \$fpath)"
echo " autoload -Uz compinit && compinit"
fi
fi
echo
print_success "Installation complete!"
echo
# Test if git recognises the command
if command -v git-ignore >/dev/null 2>&1; then
print_success "git-ignore command is available"
# Test if it works as a git subcommand
if git ignore help >/dev/null 2>&1; then
print_success "git ignore subcommand is working"
else
print_warning "git ignore subcommand may need a shell restart to work"
fi
else
print_warning "git-ignore command not found. You may need to:"
echo " 1. Add $INSTALL_DIR to your PATH"
echo " 2. Restart your shell or run: source ~/.bashrc (or ~/.zshrc)"
fi
echo
echo "Usage examples:"
echo " git ignore '*.log' # Add *.log to .gitignore"
echo " git ignore add build/ node_modules/ # Add multiple patterns"
echo " git ignore remove '*.tmp' # Remove a pattern"
echo " git ignore list # List all patterns"
echo " git ignore check file.txt # Check if file is ignored"
echo
print_info "For autocomplete to work, restart your shell or source your shell config"