Skip to content

Instantly share code, notes, and snippets.

@amxv
Last active June 24, 2025 03:30
Show Gist options
  • Select an option

  • Save amxv/2d2ea632efda69ed091ac5a701606129 to your computer and use it in GitHub Desktop.

Select an option

Save amxv/2d2ea632efda69ed091ac5a701606129 to your computer and use it in GitHub Desktop.
Codex Setup Script
#!/usr/bin/env bash
# Ensure non-interactive apt operations and higher open-file limits
export DEBIAN_FRONTEND=noninteractive
ulimit -n 1048576
# Install build-essential, curl, git, and other utilities
apt-get update -qq >/dev/null
apt-get install -y -qq --no-install-recommends apt-utils >/dev/null
apt-get install -y -qq --no-install-recommends \
build-essential curl git tree jq ripgrep fd-find unzip net-tools direnv postgresql-client sqlite3 \
tmux vim neovim bat ncdu duf httpie silversearcher-ag entr watchman make cmake pkg-config libssl-dev fzf dialog \
>/dev/null
echo "✅ essential utilities installed"
# Clean apt caches to keep image size small
apt-get clean -qq >/dev/null && rm -rf /var/lib/apt/lists/*
# Symlink fdfind to fd for convenience
ln -sf "$(which fdfind)" /usr/local/bin/fd
echo "✅ symlinked fdfind to fd"
# Configure performance improvements and better default tools
cat >> ~/.bashrc << 'EOF'
# Use bat instead of cat when available (provides syntax highlighting)
if command -v batcat >/dev/null; then
alias cat='batcat'
fi
# Use ripgrep with smart case sensitivity by default (faster than grep)
alias grep='rg --smart-case'
# Use better df and du alternatives when available
if command -v duf >/dev/null; then
alias df='duf'
fi
if command -v ncdu >/dev/null; then
alias du='ncdu'
fi
# Environment variable configuration
export EDITOR=vim
export VISUAL=vim
# Better bash history configuration
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
# Enable programmable completion features
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
EOF
echo "✅ performance optimizations configured"
#make sure uv is installed
curl -LsSf https://astral.sh/uv/install.sh | sh -s -- -q >/dev/null
echo "✅ uv installed"
# Install black and ruff globally
for pkg in ruff@latest black httpx rich typer pytest isort mypy flake8 cli-mcp; do
uv tool install "$pkg" >/dev/null
done
echo "✅ essential python packages installed"
# Install 1550-byte guard
set -euo pipefail
curl -fsSL https://gist.githubusercontent.com/amxv/a0f10f5e97d545023b945fe9f9ffdbef/raw \
-o /usr/local/bin/clw
chmod +x /usr/local/bin/clw
mkdir -p /usr/local/safe-coreutils
printf '#!/usr/bin/env bash\n/bin/cat "$@" | clw\n' \
> /usr/local/safe-coreutils/cat
chmod +x /usr/local/safe-coreutils/cat
export PATH="/usr/local/safe-coreutils:$PATH"
exec > >(clw) 2>&1
echo "✅ Line overflow guard installed"
# Install gh (GitHub CLI)
(type -p wget >/dev/null || (sudo apt-get update -qq >/dev/null && sudo apt-get install -y -qq wget >/dev/null)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt-get update -qq >/dev/null \
&& sudo apt-get install -y -qq gh >/dev/null
echo "✅ github cli installed"
# Install bun
curl -fsSL https://bun.sh/install | bash >/dev/null
echo "✅ bun installed"
cat >> ~/.bashrc << 'EOF'
shadcn() {
if [[ $1 != "add" ]]; then
echo "Usage: shadcn add <component1> <component2> ..."
return 1
fi
# Skip the "add" argument and get the rest
shift
local components=("$@")
local missing_components=()
# Determine the correct components path
local components_path
if [[ -d "./src/components/ui" ]]; then
components_path="./src/components/ui"
elif [[ -d "./components/ui" ]]; then
components_path="./components/ui"
else
echo "Error: Could not find components/ui directory"
return 1
fi
# Check which components don't exist
for component in "${components[@]}"; do
if [[ ! -f "${components_path}/${component}.tsx" ]]; then
missing_components+=("$component")
else
echo "✓ $component already exists, skipping..."
fi
done
# Install missing components
if [[ ${#missing_components[@]} -gt 0 ]]; then
echo "Installing missing components: ${missing_components[*]}"
bunx shadcn@latest add -y "${missing_components[@]}"
else
echo "All components already exist!"
fi
}
EOF
echo "✅ shadcn alias added"
cat >> ~/.bashrc << 'EOF'
# Clean Next.js build artifacts
alias clean-next='rm -rf .next'
# Fresh dependency install (clears lockfile + modules)
alias reinstall-deps='rm -rf node_modules bun.lock package-lock.json && bun install'
# Pretty directory tree while ignoring common clutter
alias filetree='tree -I "node_modules|.*|public|screenshots|.next|dist|coverage|build|dist|out|target|tmp|vendor"'
# Serve static files from current directory on port 4000
alias serve-static='http-server -p 4000 -c-1'
# Kill the process listening on a given port: kp 3000
kp () { lsof -ti tcp:"$1" | xargs kill -9; }
export -f kp
EOF
echo "✅ web dev aliases added"
# Install common JS tools globally
bun install -g --silent eslint prettier typescript @biomejs/biome tsx tldr vercel concurrently nodemon pm2 serve http-server ref-tools-mcp@latest
echo "✅ useful JS tools installed globally"
# Install dependencies
bun install --silent
echo "✅ project dependencies installed with bun"
# Download logging script to ~/logdev.sh
curl -fsSL https://gist.githubusercontent.com/amxv/8f1c3f800283d883d8adad28bffad68d/raw -o ~/logdev.sh
chmod +x ~/logdev.sh
echo "alias logdev='bash ~/logdev.sh'" >> ~/.bashrc
echo "✅ logdev script installed"
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
echo "✅ direnv hook installed"
# Install cli-mcp and initialize mcp servers
uvx cli-mcp init
echo "✅ MCP tools set up with cli-mcp"
# Configure git with sensible defaults
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global fetch.prune true
git config --global diff.colorMoved zebra
git config --global rerere.enabled true
echo "✅ git configured with sensible defaults"
# Increase inotify watch limit to avoid file-watcher issues in large projects
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf || true
# Reload sysctl configuration if possible (ignore failure in read-only filesystems)
sudo sysctl -p || true
echo "✅ inotify watch limit increased"
# Source bashrc to apply changes safely when running under 'set -u'
# Some default bashrc files reference $PS1, which may be unset in
# non-interactive shells. Temporarily disable 'nounset' to avoid the
# "PS1: unbound variable" error, then restore the setting.
set +u
export PS1=${PS1-}
source ~/.bashrc
set -u
echo "✅ bashrc refreshed"
echo "✅ Setup complete! All developer tools and optimizations are ready."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment