summaryrefslogtreecommitdiff
path: root/config/essentials
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2023-07-29 01:30:05 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2023-07-29 01:35:50 +0200
commit6a0f7b5bca424d0c3a93239e2aacb130ddad27fc (patch)
tree861120b3692a698ad473fdeb7b5848f32e7f22ff /config/essentials
parentd92788670e49842e322518930ddb60794b01ec60 (diff)
cleaned up is a file command
Diffstat (limited to 'config/essentials')
-rw-r--r--config/essentials/zsh/.zshrc27
1 files changed, 10 insertions, 17 deletions
diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc
index 195b64c..58974ba 100644
--- a/config/essentials/zsh/.zshrc
+++ b/config/essentials/zsh/.zshrc
@@ -64,17 +64,14 @@ bindkey "^['" quote-line
isTextFile()
{
- if [ ! -f "$1" ]
- then
+ [ -f "$1" ] &&
+ # will execute the file, I'd rather not have an error message
+ [ ${1::2} != "./" ] &&
+ [ ${1::1} != "/" ] &&
+ ! type "$1" > /dev/null &&
+ # is text file?
+ file -b --mime-type "$1" | grep -q "^text/" ||
return 1
- fi
-
- file_type=$(file -b --mime-type "$1")
- if [[ "$file_type" == text/* ]]
- then
- return
- fi
- return 1
}
# rehash hook
@@ -110,17 +107,13 @@ function osc7 {
}
add-zsh-hook -Uz chpwd osc7
command_not_found_handler () {
- isTextFile "$1" ||
- echo "zsh: command not found: $1" >&2
-}
-# open file with file name
-open_file() {
- if [ ${1:0:2} != "./" ] && isTextFile "$1"
+ if [[ -o interactive ]] && isTextFile "$1"
then
"$EDITOR" "$1"
+ else
+ echo "zsh: command not found: $1" >&2
fi
}
-add-zsh-hook -Uz preexec open_file
# prompt
PS1=' %B%(#.%F{1}.%F{13})[%n%b%f@%B%F{6}%m]%b%f %3~ '