-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
remove 'rotdir' | simplify and improve directory rotation #1341
Open
emrakyz
wants to merge
14
commits into
LukeSmithxyz:master
Choose a base branch
from
emrakyz:patch-10
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Commits on Jun 22, 2023
-
remove 'rotdir' | simplify and improve directory rotation
This method reads image files directly from the current directory $PWD and then uses an array to keep track of all the images. The use of Bash built-in commands like for loop and if condition ensure a faster execution because there is no need to create a subprocess for each image file. The sxiv command is run only once when the selected image is found. Furthermore, this method takes advantage of array slicing in Bash ("${images[@]:i}" "${images[@]:0:i}"). This feature allows the program to pass the images that come after the selected image (including the selected image) and before the selected image, to sxiv in correct order. This maintains the file order of the directory. The use of sort -V (version sort) also contributes to maintaining the file order as it sorts version numbers within text. In terms of efficiency, using Bash built-in operations with arrays should consume less system resources compared to lots of pipelines with multiple processes. The old method uses the rotdir script which, when combined with awk, ls, grep, setsid, and sxiv, creates multiple subprocesses. This increases the overhead for context switching between these processes, leading to more system resource usage and a slower operation than the first method. Moreover, the use of setsid -f sxiv -aio 2>/dev/null might launch sxiv multiple times, increasing the number of processes and resource usage. In terms of file ordering, the rotdir script doesn't have explicit sorting. This might not necessarily match the desired order in some cases. Lastly, the second method uses lf -remote to interact with the lf file manager. The command is run each time a new image is selected, adding an additional level of complexity and overhead to the process. The first method is more readable and maintainable due to its use of simple Bash constructs. The logic is straightforward and doesn't involve external scripts. On the other hand, the second method requires understanding the rotdir script, making it more complex to read and understand. The maintenance of this script would also need to be considered alongside the lfrc file, adding an extra layer of complexity. We can even get rid of ls and sort by using bash globbing alone but then the files are ordered lexicographically, not numerically. Meaning they would go to 10th after 1st rather than 2nd. There could be a workaround though with naming the files with leading zeroes such as 01, 02 and so on. # Detailed Explanation shopt -s nullglob This line tells bash to treat patterns which don't match any files (globs) as expanding to a null string, rather than themselves. This avoids problems in case there are no image files in the directory. dir="$0" selected_file="$1" Here, dir and selected_file are being set to the two arguments that are passed to the bash script at the end ("$PWD" and "$fx"). They are the working directory and the selected file, respectively. images=($(ls "$dir"/*.{jpg,jpeg,png,webp,bmp,tiff,tif,raw,ico,exif,heic,heif,gif,avif,jxl} | sort -V)) The ls command lists all the files in the directory that have certain image extensions. This list of files is piped (|) to sort -V, which sorts the list in version number order (which is similar to natural order for filenames). This sorted list of images is stored in the images array. [[ "${images[i]}" = "$selected_file" ]] && { sxiv -abiof "${images[@]:i}" "${images[@]:0:i}" break } done This is a for loop that iterates over each image in the images array. For each image, it checks if the image equals the selected file. If it does, the sxiv command is executed with all images from the selected one to the end of the list, followed by all images from the start of the list to the selected one. This makes it possible to navigate through the images both forward and backward, preserving the order from lf. After this, the break command is used to exit the for loop because we've found our selected image. The "$PWD" and "$fx" at the end are the arguments that are passed to the bash script. "$PWD" is the current working directory in lf, and "$fx" is the currently selected file in lf.
Configuration menu - View commit details
-
Copy full SHA for 8a3cf1e - Browse repository at this point
Copy the full SHA 8a3cf1eView commit details
Commits on Jun 30, 2023
-
Configuration menu - View commit details
-
Copy full SHA for f2e89ab - Browse repository at this point
Copy the full SHA f2e89abView commit details -
Configuration menu - View commit details
-
Copy full SHA for a8e31d6 - Browse repository at this point
Copy the full SHA a8e31d6View commit details
Commits on Jul 1, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 495a48b - Browse repository at this point
Copy the full SHA 495a48bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 0f5dcce - Browse repository at this point
Copy the full SHA 0f5dcceView commit details -
Configuration menu - View commit details
-
Copy full SHA for e2c7500 - Browse repository at this point
Copy the full SHA e2c7500View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7e0a3c4 - Browse repository at this point
Copy the full SHA 7e0a3c4View commit details -
Configuration menu - View commit details
-
Copy full SHA for 861c9a9 - Browse repository at this point
Copy the full SHA 861c9a9View commit details -
Configuration menu - View commit details
-
Copy full SHA for dfeb8e2 - Browse repository at this point
Copy the full SHA dfeb8e2View commit details
Commits on Jul 5, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 224ae5b - Browse repository at this point
Copy the full SHA 224ae5bView commit details -
Configuration menu - View commit details
-
Copy full SHA for a009de5 - Browse repository at this point
Copy the full SHA a009de5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 78a999e - Browse repository at this point
Copy the full SHA 78a999eView commit details
Commits on Jul 6, 2023
-
Configuration menu - View commit details
-
Copy full SHA for de30100 - Browse repository at this point
Copy the full SHA de30100View commit details
Commits on Jul 16, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 5342c96 - Browse repository at this point
Copy the full SHA 5342c96View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.