Skip to content

Add auto-formatting script and shellcheck static analysis with workflows. #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*.sh]
indent_style = space
indent_size = 4
end_of_line = lf
38 changes: 38 additions & 0 deletions .github/workflows/differential-shellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# From ShellCheck wiki
# https://www.shellcheck.net/wiki/GitHub-Actions

name: Differential ShellCheck
on:
push:
pull_request:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

permissions:
# required for all workflows
security-events: write

steps:
- name: Repository checkout
uses: actions/checkout@v4
with:
# Differential ShellCheck requires full git history
fetch-depth: 0

- id: ShellCheck
name: Differential ShellCheck
uses: redhat-plumbers-in-action/differential-shellcheck@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}

- if: always()
name: Upload artifact with ShellCheck defects in SARIF format
uses: actions/upload-artifact@v4
with:
name: Differential ShellCheck SARIF
path: ${{ steps.ShellCheck.outputs.sarif }}
10 changes: 10 additions & 0 deletions .github/workflows/shfmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Shell Formatting
on:
pull_request:
jobs:
shfmt:
name: runner / shfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-shfmt@v1
223 changes: 111 additions & 112 deletions bin/ml4w-hyprland-setup
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/bin/bash
# __ __ _ _ ___ __ ____ _ __ _ _
# | \/ | | | || \ \ / / | _ \ ___ | |_ / _(_) | ___ ___
# __ __ _ _ ___ __ ____ _ __ _ _
# | \/ | | | || \ \ / / | _ \ ___ | |_ / _(_) | ___ ___
# | |\/| | | | || |\ \ /\ / / | | | |/ _ \| __| |_| | |/ _ \/ __|
# | | | | |__|__ _\ V V / | |_| | (_) | |_| _| | | __/\__ \
# |_| |_|_____| |_| \_/\_/ |____/ \___/ \__|_| |_|_|\___||___/
#
#
# for Hyprland

# -----------------------------------------------------
# -----------------------------------------------------
# Folders
# -----------------------------------------------------
dir=$(dirname "$(realpath $0)")

if [[ $dir == "/usr/bin" ]] ;then
# AUR
install_mode="aur"
package_name="ml4w-hyprland"
base_directory="/usr"
bin_directory="$base_directory/bin/$package_name"
share_directory="$base_directory/share/$package_name"
lib_directory="$base_directory/lib/$package_name"
dir=$(dirname "$(realpath "$0")")

if [[ $dir == "/usr/bin" ]]; then
# AUR
install_mode="aur"
package_name="ml4w-hyprland"
base_directory="/usr"
bin_directory="$base_directory/bin/$package_name"
share_directory="$base_directory/share/$package_name"
lib_directory="$base_directory/lib/$package_name"
else
# Filesystem
install_mode="filesystem"
base_directory="$(dirname $(pwd))"
bin_directory="$base_directory/bin"
share_directory="$base_directory/share"
lib_directory="$base_directory/lib"
# Filesystem
install_mode="filesystem"
base_directory="$(dirname $(pwd))"
bin_directory="$base_directory/bin"
share_directory="$base_directory/share"
lib_directory="$base_directory/lib"
fi

install_directory="$lib_directory/install"
Expand All @@ -40,139 +40,138 @@ ml4w_directory="$HOME/.ml4w-hyprland"
backup_directory="$ml4w_directory/backup"
archive_directory="$ml4w_directory/archive"

# -----------------------------------------------------
# -----------------------------------------------------
# Version
# -----------------------------------------------------
version="$(cat $dotfiles_directory/.config/ml4w/version/name)"
version="$(cat "$dotfiles_directory"/.config/ml4w/version/name)"

# -----------------------------------------------------
# -----------------------------------------------------
# Colors
# -----------------------------------------------------
source $install_directory/includes/colors.sh
# -----------------------------------------------------
source "$install_directory"/includes/colors.sh

# -----------------------------------------------------
# -----------------------------------------------------
# Library
# -----------------------------------------------------
source $install_directory/includes/library.sh
# -----------------------------------------------------
source "$install_directory"/includes/library.sh

# -----------------------------------------------------
# -----------------------------------------------------
# Run full installation
# -----------------------------------------------------
# -----------------------------------------------------
_run_fullinstall() {
source $install_directory/header.sh
source $install_directory/packages.sh
source $install_directory/dotfiles.sh
source "$install_directory"/header.sh
source "$install_directory"/packages.sh
source "$install_directory"/dotfiles.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Check for update
# -----------------------------------------------------
# -----------------------------------------------------
_check_update() {
if [ -f ~/.config/ml4w/settings/dotfiles-folder.sh ] ;then
echo "true"
else
echo "false"
fi
if [ -f ~/.config/ml4w/settings/dotfiles-folder.sh ]; then
echo "true"
else
echo "false"
fi
}

# -----------------------------------------------------
# -----------------------------------------------------
# Run packages installation
# -----------------------------------------------------
# -----------------------------------------------------
_run_packages() {
source $install_directory/header.sh
source $install_directory/packages.sh
source "$install_directory"/header.sh
source "$install_directory"/packages.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Run dotfiles installation
# -----------------------------------------------------
# -----------------------------------------------------
_run_dotfiles() {
source $install_directory/header.sh
source $install_directory/dotfiles.sh
source "$install_directory"/header.sh
source "$install_directory"/dotfiles.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Run unstaller
# -----------------------------------------------------
# -----------------------------------------------------
_run_optional() {
source $install_directory/optional.sh
source "$install_directory"/optional.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Run unstaller
# -----------------------------------------------------
# -----------------------------------------------------
_run_uninstall() {
source $install_directory/uninstall.sh
source "$install_directory"/uninstall.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Run update
# -----------------------------------------------------
# -----------------------------------------------------
_run_update() {
source $install_directory/update.sh
source "$install_directory"/update.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Activate existing dotfiles installation
# -----------------------------------------------------
# -----------------------------------------------------
_run_activate() {
source $install_directory/activate.sh
source "$install_directory"/activate.sh
}

# -----------------------------------------------------
# -----------------------------------------------------
# Header
# -----------------------------------------------------
# -----------------------------------------------------

# -----------------------------------------------------
# -----------------------------------------------------
# Get script parameter
# -----------------------------------------------------
if [[ -z $1 ]] ;then
_run_fullinstall
# -----------------------------------------------------
if [[ -z $1 ]]; then
_run_fullinstall
else
while getopts m:vh flag
do
case "${flag}" in
m)
case ${OPTARG} in
full)
_run_fullinstall
;;
packages)
_run_packages
;;
dotfiles)
_run_dotfiles
;;
uninstall)
_run_uninstall
;;
optional)
_run_optional
;;
update)
_run_update
;;
activate)
_run_activate
;;
esac
;;
v)
echo ":: ML4W Dotfiles for Hyprland Version $version"
;;
h)
echo ":: ML4W Dotfiles for Hyprland Version $version"
echo
echo "-m full: Run full installation"
echo "-m packages: Run installation of packages only"
echo "-m dotfiles: Run the setup of the dotfiles only"
echo "-m options: Install optional packages"
echo "-m update: Check for new updates"
echo "-m unstall: Will uninstall the dotfiles"
echo "-m activate: Activate an existing dotfiles folder"
echo
echo "-v: Current version of the ML4W Dotfiles for Hyprland"
;;
esac
done
while getopts m:vh flag; do
case "${flag}" in
m)
case ${OPTARG} in
full)
_run_fullinstall
;;
packages)
_run_packages
;;
dotfiles)
_run_dotfiles
;;
uninstall)
_run_uninstall
;;
optional)
_run_optional
;;
update)
_run_update
;;
activate)
_run_activate
;;
esac
;;
v)
echo ":: ML4W Dotfiles for Hyprland Version $version"
;;
h)
echo ":: ML4W Dotfiles for Hyprland Version $version"
echo
echo "-m full: Run full installation"
echo "-m packages: Run installation of packages only"
echo "-m dotfiles: Run the setup of the dotfiles only"
echo "-m options: Install optional packages"
echo "-m update: Check for new updates"
echo "-m unstall: Will uninstall the dotfiles"
echo "-m activate: Activate an existing dotfiles folder"
echo
echo "-v: Current version of the ML4W Dotfiles for Hyprland"
;;
esac
done
fi
57 changes: 57 additions & 0 deletions fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

set -eou pipefail

usage() {
echo "Usage: $0 {fmt|check|check-apply} [file]"
exit 1
}

if [ $# -lt 1 ]; then
usage
else
command=$1
fi

if [ $# -eq 1 ]; then
file=""
else
file=$2
fi

case $command in
fmt)
if [ -z "$file" ]; then
echo "Please provide a file to format. You can provide '.' for recursion."
exit 1
fi
shfmt -w "$file"
;;
check)
if [ -z "$file" ]; then
echo "Please provide a file to check. You can provide '.' for recursion'"
exit 1
fi
if [ "$file" == "." ]; then
mapfile -t FILES < <(shfmt -f .)
shellcheck "${FILES[@]}"
else
shellcheck "$file"
fi
;;
check-apply)
if [ -z "$file" ]; then
echo "Please provide a file to check. You can provide '.' for recursion'"
exit 1
fi
if [ "$file" == "." ]; then
mapfile -t FILES < <(shfmt -f .)
shellcheck "${FILES[@]}" -f diff | git apply --allow-empty
else
shellcheck "$file" -f diff | git apply --allow-empty
fi
;;
*)
usage
;;
esac
Loading