adds vscode extensions support

Signed-off-by: Menno van Leeuwen <menno@vleeuwen.me>
This commit is contained in:
Menno van Leeuwen 2024-08-22 17:03:39 +02:00
parent aacb9de41c
commit f749c8f578
9 changed files with 133 additions and 1 deletions

View File

@ -5,4 +5,7 @@ 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" "cyan" "Exporting VSCode extensions"
code --list-extensions | jq -R -s -c 'split("\n")[:-1]' > ~/dotfiles/vscode/extensions.json
printfe "%s\n" "green" "Finished, don't forget to commit and push"

View File

@ -1,4 +1,61 @@
#!/usr/bin/env zsh
source ~/dotfiles/bin/helpers/functions.sh
source ~/dotfiles/bin/helpers/packages.sh
source ~/dotfiles/bin/helpers/vscode-extensions.sh
# Check if parameter --verbose was passed
if [ "$2" = "--verbose" ]; then
verbose=true
else
verbose=false
fi
# count entries in packages
count=$(echo $packages | wc -w)
installed=0
for package in $packages; do
pkg_status=$(dpkg -s $package 2> /dev/null | grep "Status" | cut -d " " -f 4)
if [ "$pkg_status" = "installed" ]; then
installed=$((installed + 1))
else
if [ "$verbose" = true ]; then
printfe "%s\n" "red" "$package is not installed"
fi
fi
done
printfe "%s\n" "cyan" "APT $installed/$count packages installed"
load_vscode_extensions
count_installed_extensions=0
# Loop through each extension and check if it's installed
for extension in "${extensionList[@]}"; do
result=$(code --list-extensions | grep -E "^${extension}$")
if [ -z "$result" ]; then
if [ "$verbose" = true ]; then
printfe "%s" "yellow" "Extension $extension is not installed\n"
fi
else
count_installed_extensions=$((count_installed_extensions + 1))
fi
done
if [ "$verbose" = true ]; then
printfe "%s\n" "yellow" "Expected extensions:"
for ext in "${extensionList[@]}"; do
printfe "%s\n" "blue" "$ext"
done
printfe "%s\n" "yellow" "Installed extensions:"
while IFS= read -r installed_ext; do
printfe "%s\n" "blue" "$installed_ext"
done < <(code --list-extensions)
fi
total_extensions=${#extensionList[@]}
printfe "%s\n" "cyan" "VSCode $count_installed_extensions/$total_extensions extensions installed"

View File

@ -19,6 +19,10 @@ printfe "%s\n" "cyan" "Ensuring packages are installed..."
source ~/dotfiles/bin/helpers/packages.sh
ensure_packages_installed
printfe "%s\n" "cyan" "Ensuring VSCode extensions are installed..."
source ~/dotfiles/bin/helpers/vscode-extensions.sh
ensure_vscode_extensions_installed
printfe "%s\n" "cyan" "Importing Gnome Terminal preferences..."
cat ~/dotfiles/config/gterminal.preferences | dconf load /org/gnome/terminal/legacy/profiles:/

View File

@ -55,7 +55,10 @@ ensure_packages_installed() {
fi
for package in $packages; do
if ! command -v $package &> /dev/null; then
pkg_status=$(dpkg -s $package 2> /dev/null | grep "Status" | cut -d " " -f 4)
# If pkg_status is `installed` then we don't need to install the package, otherwise if it's empty then the package is not installed
if [ -z $pkg_status ]; then
printfe "%s" "yellow" "Installing $package..."
echo -en "\r"

View File

@ -0,0 +1,34 @@
#!/usr/bin/env zsh
source ~/dotfiles/bin/helpers/functions.sh
load_vscode_extensions() {
# Clear the array before populating it
arr=()
while IFS= read -r line; do
arr+=("$line")
done < <(jq -r '.[]' ~/dotfiles/vscode/extensions.json)
# Export the array
export extensionList=("${arr[@]}")
}
ensure_vscode_extensions_installed() {
# Load extensions list from jq in ~/dotfiles/vscode/extensions.json
load_vscode_extensions
for extension in "${extensionList[@]}"; do
result=$(code --list-extensions | grep -E "^${extension}$")
if [ -z "$result" ]; then
printfe "%s" "yellow" "Installing $extension..."
code --install-extension $extension
if [ $? -ne 0 ]; then
printfe "%s\n" "red" "Failed to install $extension"
exit 1
fi
printfe "%s\n" "green" "Installed $extension"
else
printfe "%s\n" "green" "$extension is already installed"
fi
done
}

View File

@ -4,5 +4,6 @@ Usage: dotf [options] [optional parameters]
update: Pull latest changes, and update symlinks and configurations.
export: Export dconf, gsettings, and other configurations.
status: Show the status of the dotfiles repository.
help: Shows this help message

View File

@ -25,3 +25,31 @@ font='MesloLGS Nerd Font 14'
foreground-color='rgb(208,207,204)'
use-system-font=false
use-theme-colors=false
[legacy/profiles:/legacy/profiles:/legacy/keybindings]
reset-and-clear='<Primary><Shift>k'
[legacy/profiles:/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
[legacy/profiles:/legacy/profiles:/legacy/profiles:/legacy/keybindings]
reset-and-clear='<Primary><Shift>k'
[legacy/profiles:/legacy/profiles:/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

1
vscode/extensions.json Normal file
View File

@ -0,0 +1 @@
["davidanson.vscode-markdownlint","esbenp.prettier-vscode","github.copilot","github.copilot-chat","ms-azuretools.vscode-docker","ms-vscode-remote.remote-containers","vscode-icons-team.vscode-icons"]

View File

@ -10,4 +10,5 @@
"scminput": false
},
"git.autofetch": true,
"workbench.iconTheme": "vscode-icons",
}