Migrate to chezmoi

Move config files from config to chezmoi
Add script to auto install packages with DNF and Cargo
This commit is contained in:
Alexander Navarro 2024-03-01 20:25:09 -03:00
parent 110e0882c6
commit 224c7ed45c
1654 changed files with 470035 additions and 51 deletions

View file

@ -0,0 +1,32 @@
dnf-save-install() {
file="$DOTS/exports/dnf.txt"
echo "$*" >> "$file"
sort -u -o "$file" "$file"
sudo dnf install -y $(cat "$DOTS/exports/dnf.txt")
}
dnf-load-export() {
while read -r line; do
sudo dnf copr enable -y "$line"
done <"$DOTS/exports/copr.txt"
sudo dnf install -y $(cat "$DOTS/exports/dnf.txt")
}
upgrade() {
sudo dnf upgrade --refresh -y
}
# where did I get this?
mayor-upgrade() {
if [[ $(dnf check-update -q) ]]; then
echo "There are updates pending, update and reboot? [y/N]"
read -r answer
if [[ $answer == 'y' || $answer == 'Y' ]]; then
upgrade
sc-reboot
fi
fi
}

View file

@ -0,0 +1,89 @@
export FLATPAK_ALIAS_FILE="${DOTS:-$HOME/.config}/config/zsh/aliases/flatpak.zsh"
export FLATPAK_EXPORT_FILE="${DOTS:-$HOME/Desktop}/exports/flatpak-apps.txt"
fp() {
set -e
generate_flatpak_alias() {
local flatpak_alias_file=${1:-$FLATPAK_ALIAS_FILE}
[[ -f $flatpak_alias_file ]] && touch "$flatpak_alias_file"
local flatpak_binaries_dir="/var/lib/flatpak/exports/bin"
if [[ -d "$flatpak_binaries_dir" ]]; then
echo -e "\n# Auto-generated aliases for Flatpak applications\n" >> "${flatpak_alias_file}"
while read -r app; do
app_id=$(echo "$app" | awk -F'/' '{print $NF}')
alias_name=$(echo "$app_id" | awk -F'.' '{print $NF}' | tr '[:upper:]' '[:lower:]')
echo "alias $alias_name='flatpak run $app_id'" >> "${flatpak_alias_file}"
done < <(find "$flatpak_binaries_dir" -maxdepth 1 -mindepth 1)
echo "Done generating Flatpak aliases"
echo "Check ${BLD}${BLU}$flatpak_alias_file${RST} to modify auto-generated alias"
else
echo "${RED}${BLD}Error: ${YLW}$flatpak_binaries_dir${RST} directory does not exist"
fi
}
export_flatpak_apps() {
local flatpak_export_file=""${1:-$FLATPAK_EXPORT_FILE}
flatpak list --columns=application --app > "${flatpak_export_file}"
echo "${BLD}${BLU}Flatpak apps exported successfully${RST}"
}
import_flatpak_apps() {
local flatpak_export_file=${1:-$FLATPAK_EXPORT_FILE}
xargs flatpak install -y < "${flatpak_export_file}"
}
show_help() {
echo -e "${BLD}Usage: ${GRN}fp${RST}${YLW} [OPTION]${RST}"
echo -e ""
echo -e "${BLD} Options:${RST}"
echo -e "${YLW} -e, export ${RST}Export a list of installed Flatpak apps to a file"
echo -e "${YLW} -i, import ${RST}Install Flatpak apps from exported file"
echo -e "${YLW} -g, generate ${RST}Generate aliases for all installed Flatpak apps"
echo -e "${YLW} -h, --help ${RST}Show this help"
}
main() {
local action=$1
case $action in
"generate"|"-g")
echo -en "Enter the location to save the Flatpak alias file, \n(default: ${FLATPAK_ALIAS_FILE}): "
read -r user_alias_dir
if [[ -n "$user_alias_dir" ]]; then
FLATPAK_ALIAS_FILE="$user_alias_dir"
fi
generate_flatpak_alias "${FLATPAK_ALIAS_FILE}"
;;
"export"|"-e")
echo -en "Enter the location to save the Flatpak export file (default: ${FLATPAK_EXPORT_FILE}): "
read -r user_export_file
if [[ -n "$user_export_file" ]]; then
FLATPAK_EXPORT_FILE="$user_export_file"
fi
export_flatpak_apps "${FLATPAK_EXPORT_FILE}"
;;
"import"|"-i")
echo -en "Enter the location of the Flatpak export file to import (default: ${FLATPAK_EXPORT_FILE}): "
read -r user_export_file
if [[ -n "$user_export_file" ]]; then
FLATPAK_EXPORT_FILE="$user_export_file"
fi
import_flatpak_apps "${FLATPAK_EXPORT_FILE}"
;;
"--help"|"-h")
show_help
;;
*)
show_help
;;
esac
}
main "$@"
}

View file

@ -0,0 +1,62 @@
# SSH tunnel
ssh-tunnel() {
local_port=$1 && shift
remote_port=$1 && shift
server=$1 && shift
echo "Starting SSH Tunnel for $server"
ssh -N -L "$local_port":localhost:"$remote_port" "$server"
}
# quick wordpress in docker
dwps() {
image_name="wordpress-development"
container_build_path="$HOME/Repos/Private/docker-services/wordpress"
original_path="$PWD"
if [[ "$(docker images -q $image_name 2> /dev/null)" == "" ]] ; then
cd "$container_build_path"
docker build --tag "$image_name" .
cd "$original_path"
fi
docker run -d --rm -p 3000:80 --user 1000:1000 -v "$PWD":/var/www/html --name "$image_name" "$image_name"
}
## Create python venv
pvenv() {
[[ -n $VIRTAUL_ENV ]] && echo "Virtual enviroment already sourced" && return
dir=${1:-venv}
[[ ! -d $dir ]] && echo "Creating virtual enviroment..." && python -m venv $dir
source "$dir/bin/activate"
}
# Print bottlenecks
profzsh() {
shell=${1-$SHELL}
ZPROF=true $shell -i -c exit
}
# Pretty Help
alias bathelp='bat --plain --language=help'
help() {
"$@" --help 2>&1 | bathelp
}
fzf-jq() {
echo '' | fzf --print-query --preview="jq -r {q} <$@"
}
function ya() {
local tmp="$(mktemp -t "yazi-cwd.XXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
fi
rm -f -- "$tmp"
}

View file

@ -0,0 +1,41 @@
SEPARATOR=" │ "
FZF_SEPARATOR="│" # Same character, without whitespaces
format_values() {
values="$1"
shift
divider="$1"
shift
echo -e "$(echo "$values" | column --table --separator $divider --output-separator $SEPARATOR)"
}
tmux_switch_or_create() {
target=$1
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
tmux $change -t "$target" 2>/dev/null || (tmux new-session -d -s $target && tmux $change -t "$target"); return
}
# tm - create new tmux session, or switch to existing one. Works from within tmux too. (@bag-man)
# `tm` will allow you to select your tmux session via fzf.
# `tm irc` will attach to the irc session (if it exists), else it will create it.
tm() {
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
if [ $1 ]; then
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
fi
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0 --select-1) && tmux $change -t "$session" || echo "No sessions found."
}
ta() {
export START_DIRECTORY="$(z -l 2>&1 | fzf --height 40% --nth 2.. --reverse --inline-info +s --tac --query "${*##-* }" | sed 's/^[0-9,.]* *//')"
if [[ -z START_DIRECTORY ]]; then
exit 0
fi
export SESSION_NAME="$(basename $START_DIRECTORY)"
tmuxp load $(fd -e yml . ~/.config/tmuxp | fzf)
}