From The Compiler, 7 Years ago, written in Bash.
Embed
  1. ### Client settings (the machine (g)vim appears
  2.  
  3. # IP of the client. Since we assume it's behind a NAT and SSH tunnels are
  4. # used, this defaults to localhost if unset.
  5. client_host=""
  6.  
  7. # Port of the client. Since we're still assuming we're using SSH tunnels, port
  8. # 2222 is assumed.
  9. client_port=""
  10.  
  11. # Binary to start on the client. The first argument is an scp://-path.If
  12. # unset, gvim is used.
  13. client_bin="urxvt -e vim"
  14.  
  15. # Username to connect to the client with. If unset, we make the naive
  16. # assumption this is the username this script is run as.
  17. client_username="florian"
  18.  
  19. # DISPLAY to use on the client. If unset, :0.0 is used.
  20. client_display=""
  21.  
  22. ### End of Settings ###
  23.  
  24.  
  25. # Set the defaults
  26. server_protocol="${server_protocol:-"scp"}"
  27. server_username="${server_username:-$USER}"
  28. client_host="${client_host:-"localhost"}"
  29. client_port="${client_port:-2222}"
  30. client_bin="${client_bin:-"gvim"}"
  31. client_username="${client_username:-$USER}"
  32. client_display="${client_display:-":0.0"}"
  33. file="$1"
  34.  
  35. ssh_connection=( $SSH_CONNECTION ) # split it
  36.  
  37. if [[ -z "$server_host" ]]; then # no IP set
  38.         if [[ -n "$SSH_CONNECTION" ]]; then # SSH_CONNECTION set
  39.                 server_host="${ssh_connection[2]}"
  40.         else
  41.                 server_host=$(wget -q -O- http://www.wgetip.com/)
  42.         fi
  43. fi
  44.  
  45. if [[ -z "$server_host" ]]; then # still no IP set
  46.         echo "ERROR: Could not find the IP of the server!"
  47.         echo "If it is static, please specify it in the settings"
  48.         exit 1
  49. fi
  50.  
  51. if [[ -z "$server_port" ]]; then
  52.         if [[ -n "$SSH_CONNECTION" ]]; then
  53.                 server_port="${ssh_connection[3]}"
  54.         else      
  55.                 server_port=22
  56.         fi        
  57. fi                
  58.                  
  59. if file=$(readlink -f "$file") && [[ -r "$file" ]]; then
  60.         true      
  61. else              
  62.         echo "ERROR: File does not exist or is unreadable!"
  63.         exit 1    
  64. fi                
  65.                  
  66. file=$(printf '%q' "$file")
  67.                  
  68. ssh -p "${client_port}" "${client_username}@${client_host}" \
  69.        "export DISPLAY='$client_display'; $client_bin '${server_protocol}://${server_username}@${server_host}:${server_port}/${file}'"