AnSnarkista

dmenu_recent (adaptado a lxterminal)

Feb 11th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Originally based on code by Dieter Plaetinck.
  4. # Pretty much re-written by Mina Nagy (mnzaki)
  5.  
  6. DMENU_OPTIONS=" -y 350 -h 50 -fn "Xirod:normal" -dim 0.5"
  7. dmenu_cmd="dmenu $DMENU_OPTIONS"
  8. terminal="lxterminal -e"
  9. max_recent=199 # Number of recent commands to track
  10.  
  11. cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu-recent"
  12. recent_cache="$cache_dir/recent"
  13. rest_cache="$cache_dir/all"
  14. known_types=" background terminal "
  15.  
  16. config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-recent"
  17. mkdir -p "$cache_dir"
  18. mkdir -p "$config_dir"
  19. touch "$recent_cache"
  20.  
  21. IFS=:
  22. if stest -dqr -n "$rest_cache" $PATH 2>/dev/null; then
  23. stest -flx $PATH | sort -u | grep -vf "$recent_cache" > "$rest_cache"
  24. fi
  25.  
  26. IFS=" "
  27. cmd=$(cat "$recent_cache" "$rest_cache" | $dmenu_cmd -p Execute: "$@") || exit
  28.  
  29. if ! grep -qx "$cmd" "$recent_cache" &> /dev/null; then
  30. grep -vx "$cmd" "$rest_cache" > "$rest_cache.$$"
  31. mv "$rest_cache.$$" "$rest_cache"
  32. fi
  33.  
  34. echo "$cmd" > "$recent_cache.$$"
  35. grep -vx "$cmd" "$recent_cache" | head -n "$max_recent" >> "$recent_cache.$$"
  36. mv "$recent_cache.$$" "$recent_cache"
  37.  
  38. # Figure out how to run the command based on the command name, disregarding
  39. # arguments, if any.
  40. word0=${cmd%% *}
  41. match="^$word0$"
  42.  
  43. get_type () {
  44. while type=$(echo $known_types | xargs -n1 | $dmenu_cmd -p Type:); do
  45. [[ $known_types =~ " $type " ]] || continue
  46. echo "$word0" >> "$config_dir/$type"
  47. break
  48. done
  49. echo $type
  50. }
  51.  
  52. if ! type=$(grep -lx "$match" -R "$config_dir"); then
  53. type=$(get_type)
  54. else
  55. type=${type##*/}
  56. if ! [[ $known_types =~ " $type " ]]; then
  57. rm "$config_dir/$type"
  58. type=$(get_type)
  59. fi
  60. fi
  61.  
  62. [[ "$type" = "background" ]] && exec $cmd
  63. [[ "$type" = "terminal" ]] && exec $terminal "$cmd"
  64. #[[ "$type" = "terminal_hold" ]] && exec $terminal sh -c "$cmd ; echo Press Enter to kill me... && read line"
Advertisement
Add Comment
Please, Sign In to add comment