Skip to content

Commit

Permalink
Fixes (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvatsal60 authored Jul 12, 2024
2 parents b02a367 + 1df98d2 commit b6e1ae4
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 167 deletions.
Empty file modified .aliases.sh
100644 → 100755
Empty file.
71 changes: 56 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
{
"image" : "mcr.microsoft.com/devcontainers/base:jammy",
"postCreateCommand": "curl -fsSL https://raw.githubusercontent.com/gvatsal60/Linux-Aliases/HEAD/main.sh | sh",
"customizations": {
"vscode": {
"extensions": [
"streetsidesoftware.code-spell-checker",
"esbenp.prettier-vscode",
"Gruntfuggly.todo-tree",
"DavidAnson.vscode-markdownlint",
"bierner.markdown-emoji",
"timonwong.shellcheck",
"foxundermoon.shell-format"
]
}
"capAdd": [
"SYS_PTRACE"
],
"customizations": {
"vscode": {
"extensions": [
"streetsidesoftware.code-spell-checker",
"esbenp.prettier-vscode",
"Gruntfuggly.todo-tree",
"DavidAnson.vscode-markdownlint",
"MindpathTechnologyLimited.code-error-lens",
"gurumukhi.selected-lines-count",
"bradzacher.vscode-copy-filename",
"PKief.material-icon-theme",
"timonwong.shellcheck",
"foxundermoon.shell-format"
],
"settings": {
"editor.bracketPairColorization.enabled": true,
"editor.comments.insertSpace": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"editor.tabCompletion": "on",
"editor.tabSize": 2,
"editor.trimAutoWhitespace": true,
"explorer.confirmDelete": false,
"extensions.autoUpdate": true,
"extensions.ignoreRecommendations": true,
"files.autoSave": "afterDelay",
"files.eol": "auto",
"files.exclude": {
"**/.vscode": true
},
"search.exclude": {
"**/*.code-search": true,
"**/*.git": true,
"**/*.vscode-server": true,
"**/bower_components": true,
"**/node_modules": true
},
"windows.title": "${folderPath}",
"workbench.iconTheme": "material-icon-theme",
"workbench.startupEditor": "none"
}
}
}
},
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"mounts": [
"source=${localWorkspaceFolder}/snippets,target=${containerWorkspaceFolder}/.vscode,type=bind"
],
"postCreateCommand": "curl -fsSL https://raw.githubusercontent.com/gvatsal60/Linux-Aliases/HEAD/install.sh | sh",
"runArgs": [
"--rm",
"--name=vsc-${localEnv:USER}-${containerWorkspaceFolderBasename}-${devcontainerId}"
]
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
name: ShellCheck

on:
pull_request:
branches: ["*"]
push:
branches:
- master

jobs:
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest

defaults:
run:
shell: bash

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install ShellCheck
run: sudo apt update && sudo apt install shellcheck -y

- name: Run ShellCheck
run: |
shellcheck *.sh
if [ $? -ne 0 ]; then
echo "ShellCheck Detected Errors!!!"
exit 1
fi
- name: Install shfmt
run: |
sudo apt install shfmt -y
- name: Format Shell Scripts
run: |
find . -name "*.sh" -exec shfmt -w -i 2 {} \;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# https://github.com/codacy/codacy-analysis-cli.

name: Codacy Security Scan

on:
push:
branches: ["master"]
Expand All @@ -21,10 +20,8 @@ on:
branches: ["master"]
schedule:
- cron: "17 16 * * 5"

permissions:
contents: read

jobs:
codacy-security-scan:
permissions:
Expand All @@ -37,7 +34,6 @@ jobs:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@v4

# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b
Expand All @@ -53,9 +49,8 @@ jobs:
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647

# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name: Markdown Lint

on:
push:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Markdown Lint
uses: DavidAnson/markdownlint-cli2-action@v16
with:
Expand Down
2 changes: 1 addition & 1 deletion .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MD013:
line_length: 100
line_length: 999
51 changes: 48 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
repos:
# Syncs pre-commit dependencies with the latest versions.
- repo: https://github.com/mxr/sync-pre-commit-deps
rev: "v0.0.1"
hooks:
- id: sync-pre-commit-deps
# Pre-commit hooks for general file checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: name-tests-test
- id: pretty-format-json
args: [--autofix, --no-ensure-ascii, --no-sort-keys]
- id: requirements-txt-fixer
- id: trailing-whitespace
# ShellCheck hook for linting shell scripts
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
rev: "v0.10.0.1"
hooks:
- id: shellcheck
name: shellcheck
description: This hook runs shellcheck for linting shell scripts

# Bashate hook for linting shell scripts
- repo: https://github.com/openstack/bashate
rev: 2.1.1
rev: "2.1.1"
hooks:
- id: bashate
name: bashate
description: This hook runs bashate for linting shell scripts
entry: bashate
language: python
types: [shell]
# Yamlfmt for formatting YAML files
- repo: https://github.com/google/yamlfmt
rev: "v0.13.0"
hooks:
- id: yamlfmt
# Codespell for detecting common misspellings in code
- repo: https://github.com/codespell-project/codespell
rev: "v2.3.0"
hooks:
- id: codespell
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Linux-Aliases 🖥️

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://img.shields.io/github/license/gvatsal60/Linux-Aliases)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/gvatsal60/Linux-Aliases/ShellCheck.yml)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![build status](https://github.com/gvatsal60/Linux-Aliases/actions/workflows/ShellCheck.yaml/badge.svg)](https://github.com/gvatsal60/Linux-Aliases/actions/workflows/ShellCheck.yaml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/gvatsal60/Linux-Aliases/master.svg)](https://results.pre-commit.ci/latest/github/gvatsal60/Linux-Aliases/HEAD)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-Yes-green.svg)](https://GitHub.com/gvatsal60/Linux-Aliases/graphs/commit-activity)
![GitHub pull-requests](https://img.shields.io/github/issues-pr/gvatsal60/Linux-Aliases)
![GitHub Issues](https://img.shields.io/github/issues/gvatsal60/Linux-Aliases)
![GitHub forks](https://img.shields.io/github/forks/gvatsal60/Linux-Aliases)
Expand Down Expand Up @@ -33,7 +34,7 @@ To start using these aliases, follow these simple steps:
1. Run the following command in your terminal:

```sh
curl -fsSL https://raw.githubusercontent.com/gvatsal60/Linux-Aliases/HEAD/main.sh | sh
curl -fsSL https://raw.githubusercontent.com/gvatsal60/Linux-Aliases/HEAD/install.sh | sh
```

2. Depending on your operating system, you might need to
Expand Down
115 changes: 115 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/sh

##########################################################################################
# File: install.sh
# Author: Vatsal Gupta
# Date: 12-Jul-2024
# Description: Setup of custom aliases on a Linux system by downloading a
# predefined .aliases.sh file from a GitHub repository and
# integrating it into the user's shell configuration
# files (~/.bashrc, ~/.zshrc, or ~/.profile)
##########################################################################################

##########################################################################################
# License
##########################################################################################
# This script is licensed under the Apache 2.0 License.

##########################################################################################
# Global Variables & Constants
##########################################################################################
readonly FILE_NAME=".aliases.sh"
readonly FILE_LINK="https://raw.githubusercontent.com/gvatsal60/Linux-Aliases/HEAD/${FILE_NAME}"

UPDATE_RC="${UPDATE_RC:-"true"}"

##########################################################################################
# Functions
##########################################################################################
# Function: updaterc
# Description: Update shell configuration files
updaterc() {
_rc=""
if [ "${UPDATE_RC}" = "true" ]; then
case $ADJUSTED_ID in
debian | rhel)
_rc=~/.bashrc
;;
alpine | arch)
_rc=~/.profile
;;
*)
echo "Error: Unsupported or unrecognized Linux distribution ${ADJUSTED_ID}"
exit 1
;;
esac

# Check if . "${HOME}/.aliases.sh" is already defined, if not then append it
if [ -f "${_rc}" ]; then
if ! grep -qxF ". \"\${HOME}/${FILE_NAME}\"" "${_rc}"; then
echo "Updating ${_rc} for ${ADJUSTED_ID}..."
printf "\n# Sourcing custom aliases\n. \"%s/%s\"\n" "$HOME" "$FILE_NAME" >> "${_rc}"
fi
else
echo "Error: File ${_rc} does not exist."
echo "Creating the ${_rc} file... although not sure if it will work."
touch ${_rc}
printf "\n# Sourcing custom aliases\n. \"%s/%s\"\n" "$HOME" "$FILE_NAME" >> "${_rc}"
fi
fi
}

# Function: dw_file
# Description: Download file using wget or curl if available
dw_file() {
# Check if wget is available
if command -v wget >/dev/null 2>&1; then
wget -O "${HOME}/${FILE_NAME}" ${FILE_LINK}
# Check if curl is available
elif command -v curl >/dev/null 2>&1; then
curl -fsSL -o "${HOME}/${FILE_NAME}" ${FILE_LINK}
else
echo "Error: Either install wget or curl"
exit 1
fi
}

##########################################################################################
# Main Script
##########################################################################################

# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
# shellcheck source=/dev/null
. /etc/os-release

# Get an adjusted ID independent of distro variants
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
ADJUSTED_ID="debian"
elif [ "${ID}" = "alpine" ]; then
ADJUSTED_ID="alpine"
elif [ "${ID}" = "arch" ] || [ "${ID_LIKE}" = "arch" ] || (echo "${ID_LIKE}" | grep -q "arch"); then
ADJUSTED_ID="arch"
elif [ "${ID}" = "rhel" ] || [ "${ID}" = "fedora" ] || [ "${ID}" = "mariner" ] || (echo "${ID_LIKE}" | grep -q "rhel") || (echo "${ID_LIKE}" | grep -q "fedora") || (echo "${ID_LIKE}" | grep -q "mariner"); then
ADJUSTED_ID="rhel"
else
echo "Error: Linux distro ${ID} not supported."
exit 1
fi

if [ -f "${HOME}/${FILE_NAME}" ]; then
echo "File already exists: $HOME/${FILE_NAME}"
echo "Do you want to replace it (default: y)? [y/n]: "
read -r rp_conf
rp_conf="${rp_conf:-y}"
if [ "$rp_conf" = "y" ]; then
# Replace the existing file
echo "Replacing $HOME/${FILE_NAME}..."
dw_file
updaterc
else
echo "Keeping existing file: $HOME/${FILE_NAME}"
fi
else
dw_file
updaterc
fi
Loading

0 comments on commit b6e1ae4

Please sign in to comment.