Snippet #890

TTL: forever — WordwrapView raw

on 2020/08/16 0:13:06 (UTC) by Matthew Brush as Bash

  1. # Create the directory where the script will live
  2.  
  3. $ mkdir -p "$HOME/.local/bin"
  4.  
  5. # Save the script to that location, named 'geany-tail'
  6.  
  7. $ cat > "$HOME/.local/bin/geany-tail" << \EOF
  8. > #!/usr/bin/env bash
  9. > set -e
  10. > temp_file=`mktemp geany-tail-XXXXXX`
  11. > trap 'rm -f "$temp_file"' EXIT
  12. > tail $@ > "$temp_file"
  13. > geany "$temp_file"
  14. > EOF
  15.  
  16. # Make the script executable
  17.  
  18. $ chmod +x "$HOME/.local/bin/geany-tail"
  19.  
  20. # Add the script directory to $PATH environment variable
  21.  
  22. $ cat >> "$HOME/.profile" << \EOF
  23. > 
  24. > # Add local bin dir to PATH
  25. > PATH="$PATH:$HOME/.local/bin"
  26. > EOF
  27.  
  28. # Source the updated ~/.profile to update environment variable
  29.  
  30. $ . "$HOME/.profile"
  31.  
  32. # Check the script is properly accessible
  33.  
  34. $ which geany-tail
  35.  
  36. # Using it, arguments are passed directly to 'tail' command
  37. # In this example, using the last 50 lines of the file 'syslog.txt'
  38.  
  39. $ geany-tail -n 50 syslog.txt

Recent Snippets