-
-
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
An Extremely Simple and Efficient Script I Think You All Like #1308
Closed
Commits on Apr 22, 2023
-
Extremely Simple and Efficient Script I Think You Like
The inspiration: (Luke Smith's Video: "Unix Chad JUST WON'T STOP Piping!" youtu.be/w_37upFE-qw Execution Time: 0.15s to 0.30s on my system (opening a video then closing it to see the output of "time" command) Very Short Summary: 1- This script feeds the "dmenu" with a list of all videos in a hard drive. 2- File paths and extensions are removed for better readability for the dmenu list. 3- Opens the chosen video file in "mpv" using the complete paths and extensions. 4- An approach of having the least amount of lines & characters while keeping the simplicity and performance has been used. updatedb command needs to be executed at first showing the database file "~/.config/.mymlocate.db" Or the script should be changed with a new path. For example: $updatedb -o ~/.config/.mymlocate.db -U /mnt/externaldrive Thoroughly detailed explanation for everyone: temp_file=$(mktemp): This command creates a temporary file using the mktemp command and stores its path in the temp_file variable. This temporary file will be used later to store the search results. locate -d ~/.config/.mymlocate.db -b -r '.*\.\(mp4\|mkv\...)$': This command searches for files with the ".mp4" or other extension in the database located at "~/.config/.mymlocate.db". The -d flag specifies the database path, the -b flag searches for files with matching base names (ignores the path), and the -r flag allows the use of regular expressions for matching. awk -F/ '{name=$NF; gsub(/\.(mp4|mkv)$/, "", name); print name "\t" $0}': This command processes the search results obtained from the locate command. It uses / as a field separator and works on each line of the output: name=$NF: Stores the last field (file name with extension) in the name variable. gsub(/\.(mp4|mkv)$/, "", name): Removes the ".mp4" or ".mkv" file extension from the name variable. print name "\t" $0: Prints the modified file name (without extension) followed by a tab character and the original line (complete file path with the extension). > "$temp_file": Redirects the output of the previous awk command to the temporary file created earlier. chosen_file_name_and_path=$(cut -f1 "$temp_file" | dmenu -i -l 10 -p "Select a video file:"): This command reads the file names without extensions from the temporary file, presents them to the user using dmenu, and stores the user's selection in the chosen_file_name_and_path variable. The cut -f1 command extracts the file names, and the dmenu -i -l 10 -p "Select a video file:" command displays the list in a menu with a prompt. mpv "$(awk -F'\t' -v chosen="$chosen_file_name_and_path" '$1 == chosen {print $2; exit}' "$temp_file")": This command plays the selected file using mpv. It uses awk to search the temporary file for the line where the first field (file name without extension) matches the user's selection and then extracts the second field (the complete file path with the extension) to pass it as an argument to the mpv command. && rm "$temp_file": After the mpv command has finished executing, this command removes the temporary file.
Configuration menu - View commit details
-
Copy full SHA for 6476766 - Browse repository at this point
Copy the full SHA 6476766View commit details
Commits on Oct 18, 2023
-
Configuration menu - View commit details
-
Copy full SHA for fe8f0bc - Browse repository at this point
Copy the full SHA fe8f0bcView commit details
Commits on Nov 9, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 533c21c - Browse repository at this point
Copy the full SHA 533c21cView commit details
Commits on Nov 10, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 18018b1 - Browse repository at this point
Copy the full SHA 18018b1View commit details
Commits on Nov 18, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 4c80fed - Browse repository at this point
Copy the full SHA 4c80fedView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9d921b3 - Browse repository at this point
Copy the full SHA 9d921b3View commit details -
Configuration menu - View commit details
-
Copy full SHA for e259c2a - Browse repository at this point
Copy the full SHA e259c2aView commit details
Commits on Nov 19, 2023
-
Configuration menu - View commit details
-
Copy full SHA for d68ba93 - Browse repository at this point
Copy the full SHA d68ba93View commit details -
Configuration menu - View commit details
-
Copy full SHA for 539f3ac - Browse repository at this point
Copy the full SHA 539f3acView commit details -
Configuration menu - View commit details
-
Copy full SHA for b28bf32 - Browse repository at this point
Copy the full SHA b28bf32View commit details -
Configuration menu - View commit details
-
Copy full SHA for a991f09 - Browse repository at this point
Copy the full SHA a991f09View commit details
Commits on Nov 21, 2023
-
Configuration menu - View commit details
-
Copy full SHA for ca7debc - Browse repository at this point
Copy the full SHA ca7debcView 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.