Advertisement
Guest User

thun - a script to launch thunar and resize it.

a guest
Jan 14th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #! /bin/bash -x
  2. echo " dollar-pound is $#"
  3. if [ "$#" -gt "1" ]; then
  4. read -p "$* was interpreted as $# arguments. This script does not yet support multiple arguments although the actual thunar command will open multiple instances if given multiple arguments that are valid directory names. If a need to emulate this behaviour arises this script will need to be revised. [enter] to exit." # could make this a loop unil a single vaid argument was entered.
  5. exit
  6. fi
  7.  
  8. if [ "$#" = "0" ]; then
  9. PATH_DIR="$PWD"
  10. fi
  11.  
  12. if [ "$#" = "1" ]; then
  13. PATH_DIR="$1"
  14. fi
  15.  
  16. if [ !-d "$PATH_DIR" ]; then
  17. read -p "$PATH_DIR is not a directory."
  18. exit
  19. fi
  20.  
  21. DIR="${PATH_DIR##*/}"
  22.  
  23. # Setting an initial condition for a variable that may be changed later. Logically it could be left undefined but this is easier to follow.
  24. ARGUMENT_IS_SPECIAL_CASE=no
  25.  
  26. nohup thunar "$PATH_DIR" &
  27. sleep 1
  28.  
  29. # The idea below is to make a good guess at the title of the thunar window just opened and wmctrl it into shape. It will work for all explicit full paths, including / which thunar's titling mechanism treats specially, and for ~/. It will fail for other arguments like ".", "..", "~/..", "~/../other_user/dir", etc. There is probably some way to get the actual directory name, just the simple filename without a path that will work even for these, which could make this more robust. But this will do since a failure to get the name right just means the window isn't quite where it should be, which can be corrected with a couple of clicks, this will cover most likely cases, and eventually somebody will fix the damn rc.xml anyway and this won't be needed.
  30. if [ "$PATH_DIR" = "/" ]; then
  31. wmctrl -r "File System - File Manager" -e 0,0,60,1912,970
  32. ARGUMENT_IS_SPECIAL_CASE=yes
  33. fi
  34.  
  35. if [ "$PATH_DIR" = "~/" ]; then
  36. wmctrl -r "$USER - File Manager" -e 0,0,60,1912,970
  37. ARGUMENT_IS_SPECIAL_CASE=yes
  38. fi
  39.  
  40. if [ "$#" = "0" ]; then
  41. wmctrl -r "${PWD##*/} - File Manager" -e 0,0,60,1912,970
  42. ARGUMENT_IS_SPECIAL_CASE=yes
  43. fi
  44.  
  45. if [ "$ARGUMENT_IS_SPECIAL_CASE" = "no" ]; then
  46. wmctrl -r "$DIR - File Manager" -e 0,0,60,1912,970
  47. fi
  48.  
  49.  
  50. /bin/bash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement