From aeade93e13d683d45efb1ab439b4468d9a1df482 Mon Sep 17 00:00:00 2001
From: tavo-wasd <gustavo@gustavocalvo.xyz>
Date: Tue, 30 May 2023 11:47:04 -0600
Subject: [PATCH] epic management

---
 bashrc    |  2 +-
 scripts/o | 36 ++++++++++++++++++++++++++++++++++++
 scripts/p | 34 +++++++++++++++++++++++++++++++---
 3 files changed, 68 insertions(+), 4 deletions(-)
 create mode 100755 scripts/o

diff --git a/bashrc b/bashrc
index 3fcd640..28b4691 100644
--- a/bashrc
+++ b/bashrc
@@ -116,4 +116,4 @@ type systemctl 2>/dev/null 1>&2 && if systemctl -q is-active graphical.target &&
     exec startx
 fi
 
-[ -e "/usr/local/bin/afetch" ] && afetch || fetch min
+[ -e "/usr/bin/afetch" ] && afetch || fetch min
diff --git a/scripts/o b/scripts/o
new file mode 100755
index 0000000..ee3df4f
--- /dev/null
+++ b/scripts/o
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Open files
+file="$1"
+
+# If executable, run 'file' and exit
+file "$file" | grep -q "shell" && "$EDITOR" "$file" && exit
+file "$file" | grep -q "executable" && file "$file" && exit
+
+# If directory, list contents
+[ -d "$file" ] && (cd "$file" && /usr/bin/ls -A1Fx --color --group-directories-first) && exit
+
+case $file in
+    # Images
+    *.jpeg) "$IMAGE" "$file" ;;
+    *.png) "$IMAGE" "$file" ;;
+    *.jpg) "$IMAGE" "$file" ;;
+    *.gif) "$IMAGE" "$file" ;;
+    *.svg) "$IMAGE" "$file" ;;
+    # Videos
+    *.webm) "$VIDEO" "$file" ;;
+    *.mp4) "$VIDEO" "$file" ;;
+    *.flv) "$VIDEO" "$file" ;;
+    *.mkv) "$VIDEO" "$file" ;;
+    *.avi) "$VIDEO" "$file" ;;
+    *.m4v) "$VIDEO" "$file" ;;
+    # Audio
+    *.flac) "$VIDEO" "$file" ;;
+    *.mp3) "$VIDEO" "$file" ;;
+    *.ogg) "$VIDEO" "$file" ;;
+    # Documents
+    *.pdf) "$READER" "$file" ;;
+    *.csv) libreoffice "$file" ;;
+    # Other
+    *.html) "$BROWSER" "$file";;
+    *) ! [ -d "$file" ] && "$EDITOR" "$file" ;;
+esac
diff --git a/scripts/p b/scripts/p
index b810f8d..0b9ae23 100755
--- a/scripts/p
+++ b/scripts/p
@@ -2,11 +2,39 @@
 # Preview files & dirs
 file="$1"
 
+# Helps with fzf_nav visualization
+rfile() {
+    file "$1" | sed 's/,\s/\n/g'
+}
+
+# If executable, run 'file' and exit
+file "$file" | grep -q "executable" && rfile "$file" && exit
+
 # If directory, list contents
-[ -d "$file" ] && (cd "$file" && /usr/bin/ls -A1Fx --color --group-directories-first)
+[ -d "$file" ] && (cd "$file" && /usr/bin/ls -A1Fx --color --group-directories-first) && exit
 
 case $file in
-    *.csv) column -s, -t < "$file" ;;
-    *.html) links -dump "$file" ;;
+    # Images
+    *.jpeg) rfile "$file" ;;
+    *.png) rfile "$file" ;;
+    *.jpg) rfile "$file" ;;
+    *.gif) rfile "$file" ;;
+    *.svg) rfile "$file" ;;
+    # Videos
+    *.webm) rfile "$file" ;;
+    *.mp4) rfile "$file" ;;
+    *.flv) rfile "$file" ;;
+    *.mkv) rfile "$file" ;;
+    *.avi) rfile "$file" ;;
+    *.m4v) rfile "$file" ;;
+    # Audio
+    *.flac) rfile "$file" ;;
+    *.mp3) rfile "$file" ;;
+    *.ogg) rfile "$file" ;;
+    # Documents
+    *.pdf) pdftotext "$file" - || file "$file" ;;
+    *.csv) column -s, -t < "$file" || cat "$file" ;;
+    # Other
+    *.html) links -dump "$file" || cat "$file" ;;
     *) ! [ -d "$file" ] && head -n 47 "$file" && printf "\n\n  ..." ;;
 esac