Skip to content
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
wants to merge 12 commits into from

Commits on Apr 22, 2023

  1. 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.
    emrakyz authored Apr 22, 2023
    Configuration menu
    Copy the full SHA
    6476766 View commit details
    Browse the repository at this point in the history

Commits on Oct 18, 2023

  1. improve && simplify

    emrakyz authored Oct 18, 2023
    Configuration menu
    Copy the full SHA
    fe8f0bc View commit details
    Browse the repository at this point in the history

Commits on Nov 9, 2023

  1. Configuration menu
    Copy the full SHA
    533c21c View commit details
    Browse the repository at this point in the history

Commits on Nov 10, 2023

  1. Configuration menu
    Copy the full SHA
    18018b1 View commit details
    Browse the repository at this point in the history

Commits on Nov 18, 2023

  1. Configuration menu
    Copy the full SHA
    4c80fed View commit details
    Browse the repository at this point in the history
  2. Add dropdown menu

    emrakyz authored Nov 18, 2023
    Configuration menu
    Copy the full SHA
    9d921b3 View commit details
    Browse the repository at this point in the history
  3. Make dmenu case insensitive

    emrakyz authored Nov 18, 2023
    Configuration menu
    Copy the full SHA
    e259c2a View commit details
    Browse the repository at this point in the history

Commits on Nov 19, 2023

  1. Add robust error handling

    emrakyz authored Nov 19, 2023
    Configuration menu
    Copy the full SHA
    d68ba93 View commit details
    Browse the repository at this point in the history
  2. minor correction

    emrakyz authored Nov 19, 2023
    Configuration menu
    Copy the full SHA
    539f3ac View commit details
    Browse the repository at this point in the history
  3. check dash as a dependency

    emrakyz authored Nov 19, 2023
    Configuration menu
    Copy the full SHA
    b28bf32 View commit details
    Browse the repository at this point in the history
  4. minor improvements

    emrakyz authored Nov 19, 2023
    Configuration menu
    Copy the full SHA
    a991f09 View commit details
    Browse the repository at this point in the history

Commits on Nov 21, 2023

  1. Correct typo on notification

    emrakyz authored Nov 21, 2023
    Configuration menu
    Copy the full SHA
    ca7debc View commit details
    Browse the repository at this point in the history