Snippet #890
on 2020/08/16 0:13:06 (UTC) by Matthew Brush as Bash
-
# Create the directory where the script will live
-
-
$ mkdir -p "$HOME/.local/bin"
-
-
# Save the script to that location, named 'geany-tail'
-
-
$ cat > "$HOME/.local/bin/geany-tail" << \EOF
-
> #!/usr/bin/env bash
-
> set -e
-
> temp_file=`mktemp geany-tail-XXXXXX`
-
> trap 'rm -f "$temp_file"' EXIT
-
> tail $@ > "$temp_file"
-
> geany "$temp_file"
-
> EOF
-
-
# Make the script executable
-
-
$ chmod +x "$HOME/.local/bin/geany-tail"
-
-
# Add the script directory to $PATH environment variable
-
-
$ cat >> "$HOME/.profile" << \EOF
-
>
-
> # Add local bin dir to PATH
-
> PATH="$PATH:$HOME/.local/bin"
-
> EOF
-
-
# Source the updated ~/.profile to update environment variable
-
-
$ . "$HOME/.profile"
-
-
# Check the script is properly accessible
-
-
$ which geany-tail
-
-
# Using it, arguments are passed directly to 'tail' command
-
# In this example, using the last 50 lines of the file 'syslog.txt'
-
-
$ geany-tail -n 50 syslog.txt
Recent Snippets
- #177607 by robesz (11 hours ago)
- #157071 by Anonymous (747 days ago)
- #156876 by Anonymous (747 days ago)
- #154030 by Anonymous (751 days ago)
- #140524 by Anonymous (770 days ago)
- #137907 by rotense (774 days ago)