Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.9 KiB

  1. #!/usr/bin/env bash
  2. msg() {
  3. printf '>>> %s\n' "$@" >&2
  4. }
  5. dir=$(clipctl cache-dir)
  6. cache_file=$dir/line_cache
  7. log=$(mktemp)
  8. tim=$(mktemp)
  9. clipmenu_shim=$(mktemp)
  10. num_files=1500
  11. trap 'rm -f -- "$log" "$tim" "$clipmenu_shim"' EXIT
  12. if [[ $0 == /* ]]; then
  13. location=${0%/*}
  14. else
  15. location=$PWD/${0#./}
  16. location=${location%/*}
  17. fi
  18. msg 'Setting up edited clipmenu'
  19. cat - "$location/../clipmenu" > /tmp/clipmenu << EOF
  20. #!/usr/bin/env bash
  21. exec 3>&2 2> >(tee "$log" |
  22. sed -u 's/^.*$/now/' |
  23. date -f - +%s.%N > "$tim")
  24. set -x
  25. dmenu() { :; }
  26. xsel() { :; }
  27. EOF
  28. chmod a+x /tmp/clipmenu
  29. if ! (( NO_RECREATE )); then
  30. rm -rf "$dir"
  31. mkdir -p "$dir"
  32. msg "Writing $num_files clipboard files"
  33. for (( i = 0; i <= num_files; i++ )); do
  34. (( i % 100 )) || printf '%s... ' "$i"
  35. line_len=$(( (RANDOM % 10000) + 1 ))
  36. num_lines=$(( (RANDOM % 10) + 1 ))
  37. data=$(
  38. tr -dc 'a-zA-Z0-9' < /dev/urandom |
  39. fold -w "$line_len" |
  40. head -"$num_lines"
  41. )
  42. read -r first_line_raw <<< "$data"
  43. printf -v first_line '%s (%s lines)\n' "$first_line_raw" "$num_lines"
  44. printf '%d %s' "$i" "$first_line" >> "$cache_file"
  45. fn=$dir/$(cksum <<< "$first_line")
  46. printf '%s' "$data" > "$fn"
  47. done
  48. printf 'done\n'
  49. else
  50. msg 'Not nuking/creating new clipmenu files'
  51. fi
  52. msg 'Running modified clipmenu'
  53. time /tmp/clipmenu
  54. (( TIME_ONLY )) && exit 0
  55. msg 'Displaying perf data'
  56. # modified from http://stackoverflow.com/a/20855353/945780
  57. paste <(
  58. while read -r tim ;do
  59. [ -z "$last" ] && last=${tim//.} && first=${tim//.}
  60. crt=000000000$((${tim//.}-10#0$last))
  61. ctot=000000000$((${tim//.}-10#0$first))
  62. printf "%12.9f %12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9} \
  63. ${ctot:0:${#ctot}-9}.${ctot:${#ctot}-9}
  64. last=${tim//.}
  65. done < "$tim"
  66. ) "$log" | less