1765 Commits

Author SHA1 Message Date
Emre AKYÜZ
d08eea1cf5
check files with no extensions 2023-07-07 03:42:37 +03:00
Emre AKYÜZ
fe6b9043b8
increased safety 2023-07-07 03:27:50 +03:00
Emre AKYÜZ
62618ae588
increased safety | exclude dotfiles | check root 2023-07-01 04:13:50 +03:00
Emre AKYÜZ
f313b6c0f5
Fix File Naming Conventions for Unix Environment
Luke mentions about Unix naming conventions on his videos. Here is a script to increase consistency according to Unix conventions for all file names in parallel, very easily and fast in a safe way.

Luke also asks: "What do you think about naming files with underscores instead of dashes?", stating his worry about the usage of underscores seems like a "soydev" thing 😂. I give my opinion below. Actually the justification is objective compared to an opinion.

### What The Script Does

**1.** Check if the item is a directory. If so;

- **a)** Remove non-English characters.
- **b)** Replace spaces, dots, and dashes with underscores.
- **c)** Remove consecutive underscores.
- **d)** Convert the name to lowercase.
- **e)** Remove any other special characters.
- **f)** If the resulting name is empty, set it to "untitled".
- **g)** Every file or directory should start and end with an alphanumeric character.

**2.** If the item is a file, apply the same transformations as for directories, but keep the file extension intact.

**3.** Check if the original name and the new name are different. If so, and if a file or directory with the new name already exists, create a unique name.

- The script can use Dash and parallel processes, ensuring safety and performance with a subshell environment. Therefore it can even rename more than 100.000 files that have extremely weird names in 30 seconds (I have tested bash built-in functions, tr, awk and sed. None of them was faster than sed for this task, awk was very close but still slower).

**Examples of How Every File Should Look:** this_is_an_example_directory_name  **OR**  this_is_an_example_video_file.mp4

### Why "_" is Preferred Instead of a Space or a Dot or a Dash

In Unix environments, it is generally recommended to replace spaces in filenames with underscores (_), rather than dots (.) or dashes (-). This is because underscores are more commonly used and supported by Unix utilities and programming languages.

Dots (.) are typically used as a separator between a file's name and its extension, so using them to replace spaces can lead to confusion and errors. Dashes (-) are sometimes used in place of spaces, but they can be problematic because they are often used as a command-line option delimiter in Unix, which can lead to unexpected behavior.

- **Readability:** Underscores make file and directory names more readable, as they clearly separate words and components in the name, whereas spaces can be easily overlooked, and dots can be mistaken for file extensions.

- **Compatibility:** Some command line tools and scripts may not handle file names with spaces or dots properly without additional configuration or escaping. Underscores, on the other hand, do not require special handling and are generally better supported across various tools and environments.

- **URL encoding:** When sharing file paths in URLs or web applications, spaces and dots may require URL encoding (e.g., replacing spaces with "%20" and dots with "%2E"), which can make the URLs less readable and more cumbersome to work with

### The Reason Behind Using a Subshell Environment

Subshells are used in the script to isolate the execution environment of each parallel process. This isolation ensures that the processes do not interfere with each other, as they have their own separate environments, including local variables and function definitions. This separation is particularly important when running multiple processes in parallel, as it reduces the risk of race conditions and other synchronization issues.

Using subshells in the script also simplifies the process of launching parallel processes. By executing the process_item function within a subshell, the script can easily leverage the -P flag of xargs to specify the maximum number of parallel processes to run. This results in improved performance and efficiency when processing a large number of files and directories.

### The Benefit of Removing Non-English Characters

- **Compatibility:** Non-English characters can cause compatibility issues with some tools, applications, or systems that are not properly configured to handle them. By removing these characters, you reduce the risk of encountering issues related to character encoding and ensure broader compatibility across different environments.

- **Consistency:** Standardizing file and directory names by removing non-English characters can make it easier to organize, search, and manage your files. It helps maintain a consistent naming convention across your file system, which can be beneficial for both human users and automated processes.

- **Accessibility:** Using only English characters in file and directory names can improve accessibility for users who may not be familiar with non-English characters or languages. This can be particularly important in multi-user or multi-language environments where not all users might be comfortable with non-English characters.

### A Lot More Details
- find . -depth -name '*' -print0: This find command searches for all files and directories recursively in the current directory (.). -depth ensures that the directory tree is traversed depth-first, and -name '*' matches all items. -print0 prints the results separated by a null character (useful for handling filenames with spaces or special characters).

- | xargs -0 -n1 -P10 -I{} sh -c '...': The find command output is piped (|) to xargs. The -0 option tells xargs to expect null-terminated items. -n1 processes one item at a time. -P10 runs 10 parallel processes. -I{} sets the placeholder for input items. sh -c '...' runs a shell script with the given commands for each input item.

- generate_unique_name() { ... }: This is a function that generates a unique name for a file or directory. It takes three arguments: the base name, the extension (if any), and the destination path. It increments a counter and appends it to the base name until a unique name is found, then returns the unique name.

- process_item() { ... }: This is the main function that processes a single file or directory path. It sanitizes the name and renames the item if needed.

- [ "$item_path" = "." ] && return: This line checks if the item path is the current directory (.). If it is, the function returns without doing anything.

- dir_name=$(dirname "$item_path"); base_name=$(basename "$item_path"): These commands extract the directory name and base name from the item path.

- if [ -d "$item_path" ]; then ... else ... fi: This conditional block checks if the item is a directory (-d) and processes it accordingly.

- new_name=$(echo "$base_name" | sed -E "s/[^a-zA-Z0-9 _.-]+//g; s/[ .-]+/_/g; s/_+/_/g; s/^_//; s/_$//; s/(.*)/\L\1/"): This line uses sed to sanitize the base name by removing unwanted characters, replacing spaces and periods with underscores, and converting the name to lowercase. The -E flag enables extended regular expressions.

- [ -z "$new_name" ] && new_name="untitled": If the new name is empty, it is set to "untitled".

- file_ext="${base_name##*.}" base_name_no_ext="${base_name%.*}": For files, this line extracts the file extension and the base name without the extension.

- new_name="${new_base_name_no_ext}.${file_ext}": For files, this line constructs the new file name with the sanitized base name and the original file extension.

- if [ "$base_name" != "$new_name" ]; then ... fi: This conditional block checks if the original name and the new name are different.

- [ -e "${dir_name}/${new_name}" ] && new_name=$(generate_unique_name "${new_name%.*}" "${new_name##*.}" "$dir_name"): If the new name already exists, the generate_unique_name function is called to get a unique name.

- mv "$item_path" "${dir_name}/${new_name}" 2>/dev/null || true: This line moves (renames) the item to the new path with the sanitized name. If an error occurs, it is redirected to /dev/null (ignored) and the script continues executing due to the || true.

- process_item "{}": This line calls the process_item function with the input item path (represented by {}) as the argument.

- ' 2>/dev/null: This part of the script suppresses any error messages by redirecting the standard error output to /dev/null.
2023-05-10 04:13:36 +00:00
pony-montana
b2833f8a67
change requested by lf-git after update. (#1319) 2023-05-02 19:49:56 +00:00
Austen
e1302c897e
dwmblocks update on song change (#1318) 2023-05-01 16:15:11 +00:00
Luke Smith
77fd62b9f3
Merge branch 'master' of github.com:LukeSmithxyz/voidrice 2023-04-20 09:21:17 -04:00
Luke Smith
65378ab944
sb-price improvements 2023-04-20 08:48:34 -04:00
Luke Smith
b719590427
use built-ins, close #1297 2023-04-20 08:47:39 -04:00
anggatd
c08949ebd2
Change LibreOffice binaries to libreoffice (#1294)
In the current update, the libreoffice package doesn't have any binary for libreoffice writer, calc, impress, draw, etc. So it's better to open all of the document using the 'libreoffice' binary as it can work in the old version of libreoffice as well as the new one.
2023-04-20 12:32:31 +00:00
snailed
d4ff2ebaf3
fix shellcheck (#1301)
Shellcheck wines when printf doesn't get an argument
2023-04-12 12:11:29 +00:00
Mathieu Rollet
5c92a1770f
Set GOMODCACHE to comply with XDG (#1299)
If GOMODCACHE is not set, it defaults to $GOPATH/pkg/mod
cf. https://go.dev/ref/mod#environment-variables
2023-04-12 12:10:42 +00:00
RealAestan
a94ee62680
dmenuunicode: don't use variables in the printf format string (#1284)
It works but the good practice is to use `printf "..%s.." "$foo"`
see https://www.shellcheck.net/wiki/SC2059
2023-04-03 14:07:54 +00:00
Luke Smith
5a6c56d565
efficiency and fail tweaks 2023-03-31 09:44:59 -04:00
Luke Smith
749f74f84e
Merge branch 'LalleSX-patch-1' 2023-03-24 17:49:43 -04:00
Luke Smith
07b0fbcce2
fix name 2023-03-24 17:49:38 -04:00
Lalle
a558356ecf
Added Larbs commits RSS 2023-03-24 21:10:26 +01:00
Luke Smith
4537bce2c2
check scripts to avoid rerunning remapd 2023-03-23 22:06:10 -04:00
Luke Smith
0e2cd987dc
Merge branch 'master' of github.com:LukeSmithxyz/voidrice 2023-03-20 09:50:29 -04:00
Luke Smith
fd964d54b6
customizable wttr/rate urls, sb-price improvements 2023-03-20 09:50:18 -04:00
Axel
b394c5f772
Added video.desktop file. (#1288)
Updated mimeapps.list to include mp4 files.
Closes #1271
2023-03-20 12:11:07 +00:00
Luke Smith
37930fdf57
use stig over tremc by default 2023-03-01 13:38:22 -05:00
HelionSmoker
2062e8110c
SQLite ~/ cleanup (#1283) 2023-02-23 12:33:45 +00:00
appeasementPolitik
2e5226545b
maimpick: hide cursor when selecting area (#1282)
Normally when making a screenshot of an area there's still a bit of the cursor that can be seen, this hides it.
2023-02-22 22:21:55 +00:00
Luke Smith
6c92dfa4eb
Merge branch 'iStagnant-master' 2023-02-21 10:27:29 -05:00
Luke Smith
d292d927f1
use android name in fsname 2023-02-21 10:27:08 -05:00
iStagnant
89f8506d85 Made mounter not show already mounted android devices in the mounting prompt 2023-02-20 23:16:20 +02:00
Jameson
27c00576c2
update tutorialvids (#1276)
remove duplicate status bar and align
2023-02-20 12:01:52 +00:00
Luke Smith
762eadd9d1
fix #1275 2023-02-17 12:12:10 -05:00
Luke Smith
ad6ecdb3fc
Merge branch 'master' of github.com:LukeSmithxyz/voidrice 2023-02-17 11:01:19 -05:00
Luke Smith
b04d4c9ac8
mounter improvements, old scripts removed
now checks fstab for info, also one less android prompt
2023-02-17 11:01:07 -05:00
sudo-Tiz
8dce96b986
add dwmblock tutorial video to tutorialvids script (#1274) 2023-02-17 15:32:44 +00:00
Luke Smith
a2e767e4f4
other aliases 2023-02-17 10:18:01 -05:00
Luke Smith
185ac25e52
mount drives with user's ownership 2023-02-17 10:17:35 -05:00
Stagnant
335c1bc8af
Fixed android device not mounting to root owned directories (#1273) 2023-02-17 14:31:44 +00:00
Luke Smith
12167f3dda
fix #1268, use sudo -A, var rename 2023-02-13 08:12:40 -05:00
Luke Smith
537464795b
Merge branch 'HelionSmoker-master' 2023-02-12 09:00:31 -05:00
Luke Smith
de4b34cd32
read file only once 2023-02-12 09:00:23 -05:00
HelionSmoker
d8f386d512
Switch to kebab-case for file name 2023-02-12 13:33:34 +02:00
HelionSmoker
fe198c960f
Rewrite sb-forecast 2023-02-12 12:24:10 +02:00
Luke Smith
e0331ad0e7
Merge branch 'master' of github.com:LukeSmithxyz/voidrice 2023-02-09 11:53:03 -05:00
Luke Smith
c5f4c6c9f4
Merge branch 'ssnailed-patch-1' 2023-02-09 11:52:55 -05:00
Luke Smith
88477d8497
use bash procsub 2023-02-09 11:52:47 -05:00
Luke Smith
9bf90a1b72
Merge branch 'patch-1' of https://github.com/ssnailed/voidrice into ssnailed-patch-1 2023-02-09 11:51:29 -05:00
Luca Bilke
457539c043 remove complexity 2023-02-09 17:11:16 +01:00
Luke Smith
505d86c848
Merge branch 'patch-1' of https://github.com/ssnailed/voidrice into ssnailed-patch-1 2023-02-09 09:50:36 -05:00
Luca Bilke
ec1914e0b9 fix broken trap 2023-02-09 15:39:31 +01:00
HelionSmoker
ca000f5fe4
Python ~/ cleanup (#1264) 2023-02-09 14:37:31 +00:00
Luke Smith
0567be0efe
Merge branch 'patch-1' of https://github.com/ssnailed/voidrice into ssnailed-patch-1 2023-02-09 09:22:27 -05:00
Luke Smith
a4784f9faa
silent sourcing error if absent 2023-02-09 09:19:49 -05:00