Skip to content

Instantly share code, notes, and snippets.

@cesalazar
Created April 21, 2024 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesalazar/0322ae88e209de9aebe4748b6b7cde51 to your computer and use it in GitHub Desktop.
Save cesalazar/0322ae88e209de9aebe4748b6b7cde51 to your computer and use it in GitHub Desktop.
Open config files in $EDITOR
#!/bin/bash
#
# Provides easy access to editing config files.
files=
list_configs() {
printf "%s\n" "Configs available:" " "
sed -n '/case $i in/,/esac/p' "$0" \
| sed -n 's/^\s*\([^)]*\))\s.*/\1/p' \
| sed 's/)//g' \
| grep -v -E '^\*$|^c$'
}
while getopts ":l" opt; do
case $opt in
l)
list_configs
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
set_file() {
files="$files $1"
}
for i in "$@"; do
case $i in
c) set_file "$HOME/bin/c" ;; # Always first
at|atuin) set_file "$HOME/.config/atuin/config.toml" ;;
cb|clipbread) set_file "$HOME/.config/clipbread/config.js" ;;
con|conky) set_file "$HOME/.config/conky/config" ;;
d|du|dunst) set_file "$HOME/.config/dunst/dunstrc" ;;
exr|exresources) set_file "$HOME/.extend.Xresources" ;;
ga|gal|git-aliases) set_file "$HOME/.gitaliases" ;;
gh|gh-cli) set_file "$HOME/.config/gh/config.yml" ;;
g|git) set_file "$HOME/.gitconfig" ;;
i|i3) set_file "$HOME/.config/i3/config" ;;
j|jr|jrnl) set_file "$HOME/.config/jrnl/jrnl.yaml" ;;
p|poly|polybar) set_file "$HOME/.config/polybar/config" ;;
v|vim) set_file "$HOME/.vim/.vimrc" ;;
xr|xresources) set_file "$HOME/.Xresources" ;;
zp|zprezto) set_file "$HOME/.zpreztorc" ;;
z|zsh) set_file "$HOME/.zshrc" ;;
*) printf "%s\n" "$i is not a valid config" ;;
esac
done
if [ ! "$files" ]; then
printf "%s\n" "$(list_configs)"
exit 1
fi
printf "%s" "$files" | xargs -o "${EDITOR:-vim}"
exit 0
# vim: fdm=marker tabstop=2 softtabstop=2 shiftwidth=2 expandtab:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment