Skip to content

Commit

Permalink
fix(dotfiles): 🐛 fix chmod.aliases.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Dec 14, 2024
1 parent 08cb525 commit 6f3318a
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 149 deletions.
233 changes: 139 additions & 94 deletions lib/aliases/chmod/README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,154 @@
<!-- markdownlint-disable MD033 MD041 MD043 -->

<img
src="https://kura.pro/dotfiles/v2/images/logos/dotfiles.svg"
alt="dotfiles logo"
alt="Dotfiles logo"
width="66"
align="right"
/>

<!-- markdownlint-enable MD033 MD041 -->

# Dotfiles (v0.2.469)

Simply designed to fit your shell life 🐚
**Simply designed to fit your shell life 🐚**

Check notice on line 12 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L12

Emphasis used instead of a heading

![Dotfiles banner][banner]

## 🅲🅷🅼🅾🅳 🅰🅻🅸🅰🆂🅴🆂

These aliases provide shortcuts for the chmod command to help you
quickly change the permissions of files and directories. To use them,
add the following lines to your .bashrc or .bash_profile file.

### Change permissions

- `000`: (chmod a-rwx) sets permissions so that, (U)ser / owner can't
read, can't write and can't execute. (G)roup can't read, can't write
and can't execute. (O)thers can't read, can't write and can't execute.
- `400`: (chmod a-rw) sets permissions so that, (U)ser / owner can't
read, can't write and can execute. (G)roup can't read, can't write and
can execute. (O)thers can't read, can't write and can execute.
- `444`: (chmod a-r) sets permissions so that, (U)ser / owner can't
read, can't write and can execute. (G)roup can't read, can't write and
can execute. (O)thers can't read, can't write and can execute.
- `600`: (chmod a+rwx,u-x,g-rwx,o-rwx) sets permissions so that, (U)ser
/ owner can read, can write and can't execute. (G)roup can't read,
can't write and can't execute. (O)thers can't read, can't write and
can't execute.
- `644`: (chmod a+rwx,u-x,g-wx,o-wx) sets permissions so that, (U)ser /
owner can read, can write and can't execute. (G)roup can read, can't
write and can't execute. (O)thers can read, can't write and can't
execute.
- `666`: (chmod a+rwx,u-x,g-x,o-x) sets permissions so that, (U)ser /
owner can read, can write and can't execute. (G)roup can read, can
write and can't execute. (O)thers can read, can write and can't
execute.
- `755`: (chmod a+rwx,g-w,o-w) sets permissions so that, (U)ser / owner
can read, can write and can execute. (G)roup can read, can't write
and can execute. (O)thers can read, can't write and can execute.
- `764`: (chmod a+rwx,g-x,o-wx) sets permissions so that, (U)ser /
owner can read, can write and can execute. (G)roup can read, can write
and can't execute. (O)thers can read, can't write and can't execute.
- `777`: (chmod a+rwx) sets permissions so that, (U)ser / owner can
read, can write and can execute. (G)roup can read, can write and can
execute. (O)thers can read, can write and can execute.

### Change ownership

- `chgrp`: Change group ownership of files or directories.
- `chgrpr`: Change group ownership of files or directories recursively.
- `chgrpu`: Change group ownership of files or directories recursively
to the current user.
- `chmod`: Change file mode bits.
- `chmodr`: Change file mode bits recursively.
- `chmodu`: Change file mode bits recursively to the current user.
- `chmox`: Make a file executable.
- `chown`: Change file owner and group.
- `chownr`: Change file owner and group recursively.
- `chownu`: Change file owner and group recursively to the current user.

### Set permissions for specific file types

- `755d`: Set permissions of all directories to rwxr-xr-x.
- `644f`: Set permissions of all files to rw-r--r--.

### Set permissions for specific user types

- `u+x`: Add execute permission for the owner of the file.
- `u-x`: Remove execute permission for the owner of the file.
- `u+w`: Add write permission for the owner of the file.
- `u-w`: Remove write permission for the owner of the file.
- `u+r`: Add read permission for the owner of the file.
- `u-r`: Remove read permission for the owner of the file.
- `g+x`: Add execute permission for the group owner of the file.
- `g-x`: Remove execute permission for the group owner of the file.
- `g+w`: Add write permission for the group owner of the file.
- `g-w`: Remove write permission for the group owner of the file.
- `g+r`: Add read permission for the group owner of the file.
- `g-r`: Remove read permission for the group owner of the file.
- `o+x`: Add execute permission for others.
- `o-x`: Remove execute permission for others.
- `o+w`: Add write permission for others.
- `o-w`: Remove write permission for others.
- `o+r`: Add read permission for others.
- `o-r`: Remove read permission for others.

### Set permissions based on octal notation

- `000`: Set permissions to ----------
- `400`: Set permissions to r--------
- `444`: Set permissions to r--r--r--
- `600`: Set permissions to rw-------
- `644`: Set permissions to rw-r--r--.
- `664`: Set permissions to rw-rw-r--.
- `755`: Set permissions to rwxr-xr-x.
- `775`: Set permissions to rwxrwxr-x.
- `777`: Set permissions to rwxrwxrwx.
---

## 🚀 Introduction

This script provides an enhanced set of shortcuts and functions for the `chmod` command, making it easier to manage file and directory permissions. With features like input validation, recursive confirmation, and user-friendly aliases, you can efficiently customize permissions for files and directories.

Check notice on line 20 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L20

Expected: 80; Actual: 304

---

## 🛠️ Features

### 🌟 Permission Aliases

Quickly apply common permission settings with pre-defined aliases:

| Alias | Permissions | Description |

Check notice on line 30 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L30

Expected: 80; Actual: 113
|--------------|------------------|-----------------------------------------------------------------------------|
| `chmod_000` | `----------` | No permissions for anyone |

Check notice on line 32 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L32

Expected: 80; Actual: 112
| `chmod_400` | `r--------` | Read-only for the owner |

Check notice on line 33 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L33

Expected: 80; Actual: 112
| `chmod_444` | `r--r--r--` | Read-only for everyone |

Check notice on line 34 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L34

Expected: 80; Actual: 112
| `chmod_600` | `rw-------` | Read/write for the owner |

Check notice on line 35 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L35

Expected: 80; Actual: 112
| `chmod_644` | `rw-r--r--` | Read/write for the owner, read-only for others |

Check notice on line 36 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L36

Expected: 80; Actual: 112
| `chmod_666` | `rw-rw-rw-` | Read/write for everyone |

Check notice on line 37 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L37

Expected: 80; Actual: 112
| `chmod_755` | `rwxr-xr-x` | Full permissions for the owner, read/execute for others |

Check notice on line 38 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L38

Expected: 80; Actual: 112
| `chmod_764` | `rwxrw-r--` | Full permissions for the owner, read/write for the group, read-only for others |

Check notice on line 39 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L39

Expected: 80; Actual: 116
| `chmod_777` | `rwxrwxrwx` | Full permissions for everyone |

Check notice on line 40 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L40

Expected: 80; Actual: 112

---

### 🔧 Recursive Confirmation for Permissions

The `change_permission` function allows you to recursively apply permissions with a confirmation prompt, displaying the number of items affected:

Check notice on line 46 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L46

Expected: 80; Actual: 145

```bash
change_permission 755 /path/to/directory -R
```

---

### 📂 User, Group, and Others Shortcuts

Fine-tune permissions for specific user groups (owner, group, or others):

| Alias | Description |
|---------------|--------------------------------------------|
| `chmod_u+x` | Add execute permission for the owner |
| `chmod_u-x` | Remove execute permission for the owner |
| `chmod_u+w` | Add write permission for the owner |
| `chmod_u-w` | Remove write permission for the owner |
| `chmod_u+r` | Add read permission for the owner |
| `chmod_u-r` | Remove read permission for the owner |
| `chmod_g+x` | Add execute permission for the group |
| `chmod_g-x` | Remove execute permission for the group |
| `chmod_g+w` | Add write permission for the group |
| `chmod_g-w` | Remove write permission for the group |
| `chmod_g+r` | Add read permission for the group |
| `chmod_g-r` | Remove read permission for the group |
| `chmod_o+x` | Add execute permission for others |
| `chmod_o-x` | Remove execute permission for others |
| `chmod_o+w` | Add write permission for others |
| `chmod_o-w` | Remove write permission for others |
| `chmod_o+r` | Add read permission for others |
| `chmod_o-r` | Remove read permission for others |

---

### 📄 Custom Aliases for File Types

Set permissions for specific file types with ease:

| Alias | Description |
|--------------|------------------------------------------------|
| `chmod_755d` | Set permissions of all directories to `rwxr-xr-x` |
| `chmod_644f` | Set permissions of all files to `rw-r--r--` |

---

## 📦 Installation

1. Clone this repository:

```bash
git clone https://github.com/sebastienrousseau/dotfiles.git
```

2. Source the script in your shell configuration file:

```bash
echo 'source /path/to/dotfiles/chmod.sh' >> ~/.bashrc
```

3. Reload your shell:

```bash
source ~/.bashrc
```

---

## 🧑‍💻 Usage

Here are some examples of how to use the `chmod` aliases and functions:

- Apply common permissions:

```bash
chmod_644 /path/to/file
chmod_755 /path/to/directory
```

- Modify user, group, or others' permissions:

```bash
chmod_u+x /path/to/script
chmod_g-w /path/to/file
chmod_o+r /path/to/file
```

- Recursively set permissions with confirmation:

```bash
change_permission 755 /path/to/directory -R
```

---

## 🛡️ License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the `LICENSE` file for more information.

Check notice on line 143 in lib/aliases/chmod/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/aliases/chmod/README.md#L143

Expected: 80; Actual: 131

---

## 👨‍💻 Author

Created with ♥ by [Sebastien Rousseau](https://sebastienrousseau.com)

- Website: [https://sebastienrousseau.com](https://sebastienrousseau.com)
- GitHub: [https://github.com/sebastienrousseau](https://github.com/sebastienrousseau)

[banner]: https://kura.pro/dotfiles/v2/images/titles/title-dotfiles.svg
Loading

0 comments on commit 6f3318a

Please sign in to comment.