SergeySamoylov

pastebin_search

Jul 16th, 2025
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.59 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # pastebin search and copy — main app entrypoint
  3. # Inspired by Kris Occhipinti work - https://pastebin.com/2V0F9CcS
  4.  
  5. # This program is free software under the terms of
  6. # the GNU General Public License as published by
  7. # the Free Software Foundation version 3 of the License.
  8.  
  9. # DEPENDS ON menu.sh as external file for this and other projects
  10. # menu.sh included at the bottom of this file as a comment just in case.
  11.  
  12. source "$(dirname "$0")/menu.sh"
  13. declare -A paste_data # an associative array
  14.  
  15. domain="https://pastebin.com"
  16. user_options=("metalx1000" "SergeySamoylov" "exit")
  17.  
  18. clear
  19.  
  20. function show_pastes() {
  21.     echo "Pastebin User Browser"
  22.     echo "--------------------"
  23.  
  24.     # First menu - select user
  25.     user=$(menu "${user_options[@]}")
  26.     [[ "$user" == "exit" ]] && { echo "Goodbye!"; exit; }
  27.  
  28.     echo "Code snippets by ${user}:"
  29.     url="${domain}/u/${user}"
  30.  
  31.     # Process the data and store in associative array
  32.     while IFS='|' read -r title link; do
  33.         paste_data["$title"]=$link
  34.     done < <(wget -qO- "$url" | grep -A 1 "Public paste" | grep href | sed "s|<a href=\"|$domain|g;s/\">/|/g;s|</a>    </td>||g" | sed 's/^[[:space:]]*//' | awk -F'|' '{print $2"|"$1}')
  35.  
  36.     # Prepare paste options (add "Back" option)
  37.     paste_options=("${!paste_data[@]}" "Back")
  38.  
  39.     # Second menu - select paste using the same menu function
  40.     selected_title=$(menu "${paste_options[@]}")
  41.  
  42.     # Handle selection
  43.     if [[ "$selected_title" == "Back" ]]; then
  44.         # If Back selected, show user menu again
  45.         show_pastes
  46.     elif [[ -n "$selected_title" ]]; then
  47.         # If a title for a user was selected, open it
  48.         firefox "${paste_data[$selected_title]}"
  49.         exit 0
  50.     fi
  51. }
  52.  
  53. # Start the application
  54. show_pastes
  55. clear
  56.  
  57. # Just in cased you missed menu.sh in my pastebin, here it is
  58. #
  59. #!/usr/bin/env bash
  60. # menu.sh — universal fzf menu
  61. #  
  62. #  menu() {
  63. #      local -a options=("${@}")
  64. #      local formatted=()
  65. #      local i=1
  66. #  
  67. #      for option in "${options[@]}"; do
  68. #          formatted+=("$(printf "%02d) %s" "$i" "$option")")
  69. #          ((i++))
  70. #      done
  71. #  
  72. #      # Use fzf with --print-query and fallback logic
  73. #      local result query selection
  74. #  
  75. #      result=$(printf "%s\n" "${formatted[@]}" | fzf --prompt="Choose: " --height=40% --reverse --print-query)
  76. #      query=$(echo "$result" | sed -n '1p')
  77. #      selection=$(echo "$result" | sed -n '2p' | sed 's/^[0-9][0-9]*) //')
  78. #  
  79. #      # Return selection if not empty, otherwise the query
  80. #      printf "%s\n" "${selection:-$query}"
  81. #  }
  82. #  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment