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.

93 lines
1.9 KiB

  1. #!/usr/bin/env bash
  2. set -x
  3. set -e
  4. set -o pipefail
  5. dir=$(./clipctl cache-dir)
  6. cache_file=$dir/line_cache
  7. if [[ $0 == /* ]]; then
  8. location=${0%/*}
  9. else
  10. location=$PWD/${0#./}
  11. location=${location%/*}
  12. fi
  13. cat - "$location/../clipmenu" > /tmp/clipmenu << 'EOF'
  14. #!/usr/bin/env bash
  15. shopt -s expand_aliases
  16. shim() {
  17. printf '%s args:' "$1" >&2
  18. printf ' %q' "${@:2}" >&2
  19. printf '\n' >&2
  20. i=0
  21. while IFS= read -r line; do
  22. let i++
  23. printf '%s line %d stdin: %s\n' "$1" "$i" "$line" >&2
  24. done
  25. if [[ -v SHIM_STDOUT ]]; then
  26. printf '%s\n' "$SHIM_STDOUT"
  27. fi
  28. }
  29. # Cannot be an alias due to expansion order with $CM_LAUNCHER
  30. dmenu() {
  31. SHIM_STDOUT="Selected text. (2 lines)" shim dmenu "$@"
  32. }
  33. rofi() {
  34. SHIM_STDOUT="Selected text. (2 lines)" shim rofi "$@"
  35. }
  36. alias xsel='shim xsel'
  37. alias xclip='shim xclip'
  38. alias clipctl='./clipctl'
  39. EOF
  40. chmod a+x /tmp/clipmenu
  41. rm -rf "$dir"
  42. mkdir -p "$dir"
  43. cat > "$cache_file" << 'EOF'
  44. 1234 Selected text. (2 lines)
  45. 1235 Selected text 2. (2 lines)
  46. EOF
  47. cat > "$dir/$(cksum <<< 'Selected text. (2 lines)')" << 'EOF'
  48. Selected text.
  49. Yes, it's selected text.
  50. EOF
  51. ### TESTS ###
  52. temp=$(mktemp)
  53. trap 'cat "$temp"' EXIT
  54. /tmp/clipmenu --foo bar > "$temp" 2>&1
  55. # Arguments are transparently passed to dmenu
  56. grep -Fxq 'dmenu args: -l 8 --foo bar' "$temp"
  57. # Output from cache file should get to dmenu, reversed
  58. grep -Fxq 'dmenu line 1 stdin: Selected text 2. (2 lines)' "$temp"
  59. grep -Fxq 'dmenu line 2 stdin: Selected text. (2 lines)' "$temp"
  60. # xsel should copy both to clipboard *and* primary
  61. grep -Fxq 'xsel args: --logfile /dev/null -i --clipboard' "$temp"
  62. grep -Fxq 'xsel args: --logfile /dev/null -i --primary' "$temp"
  63. grep -Fxq 'xsel line 1 stdin: Selected text.' "$temp"
  64. grep -Fxq "xsel line 2 stdin: Yes, it's selected text." "$temp"
  65. CM_LAUNCHER=rofi /tmp/clipmenu --foo bar > "$temp" 2>&1
  66. # We have a special case to add -dmenu for rofi
  67. grep -Fxq 'rofi args: -l 8 -dmenu --foo bar' "$temp"