new ways 2
This commit is contained in:
parent
39868fe365
commit
6b7b3f6a2e
8
bin/actions/export.sh
Executable file
8
bin/actions/export.sh
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
source ~/dotfiles/bin/helpers/functions.sh
|
||||||
|
|
||||||
|
printfe "%s\n" "cyan" "Exporting Gnome Terminal preferences"
|
||||||
|
dconf dump /org/gnome/terminal/ > ~/dotfiles/config/gterminal.preferences
|
||||||
|
|
||||||
|
printfe "%s\n" "green" "Finished, don't forget to commit and push"
|
13
bin/actions/help.sh
Executable file
13
bin/actions/help.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source ~/dotfiles/bin/helpers/functions.sh
|
||||||
|
|
||||||
|
# Print logo
|
||||||
|
tput setaf 2
|
||||||
|
cat ~/dotfiles/bin/resources/logo.txt
|
||||||
|
println " " "cyan"
|
||||||
|
tput sgr0
|
||||||
|
|
||||||
|
# Print help
|
||||||
|
cat ~/dotfiles/bin/resources/help.txt
|
||||||
|
println " " "cyan"
|
25
bin/actions/update.sh
Executable file
25
bin/actions/update.sh
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
source ~/dotfiles/bin/helpers/functions.sh
|
||||||
|
|
||||||
|
printfe "%s\n" "cyan" "Pulling latest changes..."
|
||||||
|
git -C ~/dotfiles pull
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
printfe "%s\n" "red" "Failed to pull latest changes"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printfe "%s\n" "cyan" "Updating symlinks..."
|
||||||
|
check_or_make_symlink ~/.zshrc ~/dotfiles/zshrc
|
||||||
|
check_or_make_symlink ~/.config/Code/User/settings.json ~/dotfiles/vscode/settings.json
|
||||||
|
check_or_make_symlink ~/.config/starship.toml ~/dotfiles/config/starship.toml
|
||||||
|
|
||||||
|
printfe "%s\n" "cyan" "Ensuring packages are installed..."
|
||||||
|
source ~/dotfiles/bin/helpers/packages.sh
|
||||||
|
ensure_packages_installed
|
||||||
|
|
||||||
|
printfe "%s\n" "cyan" "Importing Gnome Terminal preferences..."
|
||||||
|
cat ~/dotfiles/config/gterminal.preferences | dconf load /org/gnome/terminal/legacy/profiles:/
|
||||||
|
|
||||||
|
printfe "%s\n" "green" "Finished, don't forget restart your terminal"
|
61
bin/dotf
Executable file
61
bin/dotf
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
source ~/dotfiles/bin/helpers/functions.sh
|
||||||
|
|
||||||
|
logo() {
|
||||||
|
tput setaf 2
|
||||||
|
cat ~/dotfiles/bin/resources/logo.txt
|
||||||
|
println " " "cyan"
|
||||||
|
tput sgr0
|
||||||
|
|
||||||
|
# Print if repo is dirty and the count of untracked files, modified files and staged files
|
||||||
|
if [[ $(git -C ~/dotfiles status --porcelain) ]]; then
|
||||||
|
printfe "%s" "yellow" "dotfiles repo is dirty "
|
||||||
|
printfe "%s" "red" "[$(git -C ~/dotfiles status --porcelain | grep -c '^??')] untracked "
|
||||||
|
printfe "%s" "yellow" "[$(git -C ~/dotfiles status --porcelain | grep -c '^ M')] modified "
|
||||||
|
printfe "%s" "green" "[$(git -C ~/dotfiles status --porcelain | grep -c '^M ')] staged "
|
||||||
|
fi
|
||||||
|
|
||||||
|
printfe "%s" "blue" "[$(git -C ~/dotfiles rev-parse --short HEAD)]"
|
||||||
|
println "" "normal"
|
||||||
|
|
||||||
|
if [[ $(git -C ~/dotfiles status --porcelain) ]]; then
|
||||||
|
# Continue?
|
||||||
|
printfe "%s" "red" "Continue anyway? [y/N] "
|
||||||
|
read -k 1
|
||||||
|
|
||||||
|
if [[ $REPLY != "y" ]]; then
|
||||||
|
println "" "normal"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
println "" "normal"
|
||||||
|
println "" "normal"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
~/dotfiles/bin/actions/update.sh $@
|
||||||
|
}
|
||||||
|
|
||||||
|
help() {
|
||||||
|
~/dotfiles/bin/actions/help.sh $@
|
||||||
|
}
|
||||||
|
|
||||||
|
exports() {
|
||||||
|
~/dotfiles/bin/actions/export.sh $@
|
||||||
|
}
|
||||||
|
|
||||||
|
# switch case for parameters
|
||||||
|
case $1 in
|
||||||
|
"update")
|
||||||
|
logo
|
||||||
|
update $@
|
||||||
|
;;
|
||||||
|
"export")
|
||||||
|
logo
|
||||||
|
exports $@
|
||||||
|
;;
|
||||||
|
"help"|"--help"|"")
|
||||||
|
help $@
|
||||||
|
;;
|
||||||
|
esac
|
142
bin/helpers/functions.sh
Executable file
142
bin/helpers/functions.sh
Executable file
@ -0,0 +1,142 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
#Color print function, usage: println "message" "color"
|
||||||
|
println() {
|
||||||
|
color=$2
|
||||||
|
printfe "%s\n" $color "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# print colored with printf (args: format, color, message ...)
|
||||||
|
printfe() {
|
||||||
|
format=$1
|
||||||
|
color=$2
|
||||||
|
shift 2
|
||||||
|
|
||||||
|
red=$(tput setaf 1)
|
||||||
|
green=$(tput setaf 2)
|
||||||
|
yellow=$(tput setaf 3)
|
||||||
|
blue=$(tput setaf 4)
|
||||||
|
magenta=$(tput setaf 5)
|
||||||
|
cyan=$(tput setaf 6)
|
||||||
|
normal=$(tput sgr0)
|
||||||
|
|
||||||
|
case $color in
|
||||||
|
"red")
|
||||||
|
color=$red
|
||||||
|
;;
|
||||||
|
"green")
|
||||||
|
color=$green
|
||||||
|
;;
|
||||||
|
"yellow")
|
||||||
|
color=$yellow
|
||||||
|
;;
|
||||||
|
"blue")
|
||||||
|
color=$blue
|
||||||
|
;;
|
||||||
|
"magenta")
|
||||||
|
color=$magenta
|
||||||
|
;;
|
||||||
|
"cyan")
|
||||||
|
color=$cyan
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
color=$normal
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
printf "$color$format$normal" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_package_installed() {
|
||||||
|
if ! command -v $1 &>/dev/null; then
|
||||||
|
println "$1 is not installed. Please install it." "red"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
println " - $1 is available." "green"
|
||||||
|
}
|
||||||
|
|
||||||
|
ask_before_do() {
|
||||||
|
printfe "%s" "yellow" "Trying to run: "
|
||||||
|
printfe "%s" "cyan" "'$@' "
|
||||||
|
read -p "Continue? [y/N]: " -n 1 -r
|
||||||
|
echo ""
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
printfe "%s" "cyan" "Running '"
|
||||||
|
printfe "%s" "yellow" "$@"
|
||||||
|
println "'..." "cyan"
|
||||||
|
|
||||||
|
# In case DRY_RUN is set to true we should just print the command and not run it
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
println "Would have run '$@'" "yellow"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
$@
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_sudo_privileges() {
|
||||||
|
if sudo -n true 2>/dev/null; then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
println "$1" "yellow"
|
||||||
|
sudo true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ask_before_do_multi() {
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
println "Would have run: $1" "yellow"
|
||||||
|
else
|
||||||
|
read -p "$1 (y/n) " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
return false
|
||||||
|
fi
|
||||||
|
return true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add_to_hosts() {
|
||||||
|
local domain=$1
|
||||||
|
local ip="127.0.0.1"
|
||||||
|
|
||||||
|
# Check if domain already exists in /etc/hosts
|
||||||
|
if ! grep -q "$domain" /etc/hosts; then
|
||||||
|
println " - adding $domain to /etc/hosts" "yellow"
|
||||||
|
echo "$ip $domain" | sudo tee -a /etc/hosts >/dev/null
|
||||||
|
else
|
||||||
|
println " - $domain already exists in /etc/hosts" "green"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if $1 is a path to a symlink, if not it will make a symlink to $2
|
||||||
|
# In case there's a file at the location of the symlink, it will backup the file
|
||||||
|
# Parameters
|
||||||
|
# $1: file to check
|
||||||
|
# $2: link location
|
||||||
|
check_or_make_symlink() {
|
||||||
|
if [ ! -L $1 ]; then
|
||||||
|
if [ -f $1 ]; then
|
||||||
|
mv $1 $1.bak
|
||||||
|
printfe "%s\n" "yellow" "Backed up $1 to $1.bak"
|
||||||
|
fi
|
||||||
|
ln -s $2 $1
|
||||||
|
printfe "%s\n" "green" "Created symlink $1 -> $2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Confirm the symlink that already exists point to the correct location
|
||||||
|
if [ -L $1 ]; then
|
||||||
|
if [ "$(readlink $1)" != $2 ]; then
|
||||||
|
printfe "%s\n" "yellow" "Symlink $1 exists but points to the wrong location"
|
||||||
|
printfe "%s\n" "yellow" "Expected: $2"
|
||||||
|
printfe "%s\n" "yellow" "Actual: $(readlink $1)"
|
||||||
|
printfe "%s\n" "yellow" "Fixing symlink"
|
||||||
|
rm $1
|
||||||
|
ln -s $2 $1
|
||||||
|
printfe "%s\n" "green" "Created symlink $1 -> $2"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
74
bin/helpers/packages.sh
Normal file
74
bin/helpers/packages.sh
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
packages=(
|
||||||
|
"zsh"
|
||||||
|
"git"
|
||||||
|
"curl"
|
||||||
|
"wget"
|
||||||
|
"vim"
|
||||||
|
"tmux"
|
||||||
|
"sl"
|
||||||
|
"just"
|
||||||
|
"libglvnd-dev"
|
||||||
|
"libwayland-dev"
|
||||||
|
"libseat-dev"
|
||||||
|
"libxkbcommon-dev"
|
||||||
|
"libinput-dev"
|
||||||
|
"udev"
|
||||||
|
"dbus"
|
||||||
|
"libdbus-1-dev"
|
||||||
|
"libsystemd-dev"
|
||||||
|
"libpixman-1-dev"
|
||||||
|
"libssl-dev"
|
||||||
|
"libflatpak-dev"
|
||||||
|
"libpulse-dev"
|
||||||
|
"libexpat1-dev"
|
||||||
|
"libfontconfig-dev"
|
||||||
|
"libfreetype-dev"
|
||||||
|
"mold"
|
||||||
|
"cargo"
|
||||||
|
"libgbm-dev"
|
||||||
|
"libclang-dev"
|
||||||
|
"libpipewire-0.3-dev"
|
||||||
|
"libpam0g-dev"
|
||||||
|
"openssh-server"
|
||||||
|
"build-essential"
|
||||||
|
"flatpak"
|
||||||
|
"meson"
|
||||||
|
"pipx"
|
||||||
|
"python3-nautilus"
|
||||||
|
"gettext"
|
||||||
|
"fzf"
|
||||||
|
"neofetch"
|
||||||
|
"screenfetch"
|
||||||
|
)
|
||||||
|
|
||||||
|
ensure_packages_installed() {
|
||||||
|
ensure_sudo_privileges "In order to install packages, please provide your password:"
|
||||||
|
|
||||||
|
# Check if packages array contains duplicates
|
||||||
|
if [ $(echo $packages | tr ' ' '\n' | sort | uniq -d | wc -l) -ne 0 ]; then
|
||||||
|
printfe "%s\n" "red" "The packages array contains duplicates"
|
||||||
|
printfe "%s\n" "yellow" "Duplicates:"
|
||||||
|
printfe "%s\n" "blue" $(echo $packages | tr ' ' '\n' | sort | uniq -d)
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for package in $packages; do
|
||||||
|
if ! command -v $package &> /dev/null; then
|
||||||
|
printfe "%s" "yellow" "Installing $package..."
|
||||||
|
echo -en "\r"
|
||||||
|
|
||||||
|
sudo apt install -y $package &> /dev/null
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
printfe "%s\n" "red" "Failed to install $package"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
printfe "%s\n" "green" "$package installed successfully"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printfe "%s\n" "green" "$package is already installed"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
8
bin/resources/help.txt
Normal file
8
bin/resources/help.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
All [] are optional parameters. And all <> are required parameters.
|
||||||
|
Usage: dotf [options] [optional parameters]
|
||||||
|
|
||||||
|
update: Pull latest changes, and update symlinks and configurations.
|
||||||
|
export: Export dconf, gsettings, and other configurations.
|
||||||
|
help: Shows this help message
|
||||||
|
|
7
bin/resources/logo.txt
Normal file
7
bin/resources/logo.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
_ ___ _ __ _ _
|
||||||
|
/\/\ ___ _ __ _ __ ___( )__ / \___ | |_ / _(_) | ___ ___
|
||||||
|
/ \ / _ \ '_ \| '_ \ / _ \/ __| / /\ / _ \| __| |_| | |/ _ \/ __|
|
||||||
|
/ /\/\ \ __/ | | | | | | (_) \__ \ / /_// (_) | |_| _| | | __/\__ \
|
||||||
|
\/ \/\___|_| |_|_| |_|\___/|___/ /___,' \___/ \__|_| |_|_|\___||___/
|
||||||
|
|
27
config/gterminal.preferences
Normal file
27
config/gterminal.preferences
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
[legacy/keybindings]
|
||||||
|
reset-and-clear='<Primary><Shift>k'
|
||||||
|
|
||||||
|
[legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9]
|
||||||
|
background-color='rgb(23,20,33)'
|
||||||
|
cursor-blink-mode='on'
|
||||||
|
cursor-shape='underline'
|
||||||
|
default-size-columns=120
|
||||||
|
default-size-rows=30
|
||||||
|
font='MesloLGS Nerd Font 14'
|
||||||
|
foreground-color='rgb(208,207,204)'
|
||||||
|
use-system-font=false
|
||||||
|
use-theme-colors=false
|
||||||
|
|
||||||
|
[legacy/profiles:/legacy/keybindings]
|
||||||
|
reset-and-clear='<Primary><Shift>k'
|
||||||
|
|
||||||
|
[legacy/profiles:/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9]
|
||||||
|
background-color='rgb(23,20,33)'
|
||||||
|
cursor-blink-mode='on'
|
||||||
|
cursor-shape='underline'
|
||||||
|
default-size-columns=120
|
||||||
|
default-size-rows=30
|
||||||
|
font='MesloLGS Nerd Font 14'
|
||||||
|
foreground-color='rgb(208,207,204)'
|
||||||
|
use-system-font=false
|
||||||
|
use-theme-colors=false
|
@ -3,4 +3,10 @@
|
|||||||
|
|
||||||
"editor.fontFamily": "MesloLGS Nerd Font",
|
"editor.fontFamily": "MesloLGS Nerd Font",
|
||||||
"terminal.integrated.fontFamily": "MesloLGS Nerd Font",
|
"terminal.integrated.fontFamily": "MesloLGS Nerd Font",
|
||||||
|
"github.copilot.enable": {
|
||||||
|
"*": true,
|
||||||
|
"plaintext": true,
|
||||||
|
"markdown": false,
|
||||||
|
"scminput": false
|
||||||
|
},
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
export PATH=$PATH:~/dotfiles/bin
|
||||||
|
|
||||||
HISTFILE=~/.histfile
|
HISTFILE=~/.histfile
|
||||||
HISTSIZE=1000
|
HISTSIZE=1000
|
||||||
SAVEHIST=1000
|
SAVEHIST=1000
|
Loading…
x
Reference in New Issue
Block a user