summaryrefslogtreecommitdiff
path: root/config/essentials/zsh/.zshrc
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2023-06-18 23:05:23 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2023-06-18 23:05:23 +0200
commit11ee207cc10e72aa96fad4715b14a84c686ad480 (patch)
treebc98d60bb59ab0fdc183c6673fe8fe143fd367bc /config/essentials/zsh/.zshrc
parent305c8e8ff1fc4a76fb42151105e119e8266df57c (diff)
parent8c5d85923a970bd60657848e1c2c6f627c4329d9 (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'config/essentials/zsh/.zshrc')
-rw-r--r--config/essentials/zsh/.zshrc38
1 files changed, 37 insertions, 1 deletions
diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc
index 96ec100..83da0f6 100644
--- a/config/essentials/zsh/.zshrc
+++ b/config/essentials/zsh/.zshrc
@@ -65,6 +65,21 @@ bindkey "^Xe" edit-command-line
bindkey "^[." insert-last-word
bindkey "^['" quote-line
+isTextFile()
+{
+ if [ ! -f "$1" ]
+ then
+ return 1
+ fi
+
+ file_type=$(file -b --mime-type "$1")
+ if [[ "$file_type" == text/* ]]
+ then
+ return
+ fi
+ return 1
+}
+
# rehash hook
zshcache_time="$(date +%s%N)"
autoload -Uz add-zsh-hook
@@ -80,14 +95,35 @@ rehash_precmd() {
# window title hooks
add-zsh-hook -Uz precmd rehash_precmd
set_wt_action () {
- print -Pn "\e]0;$1\a"
+ print -Pn '\e]0;$1\a'
}
add-zsh-hook -Uz preexec set_wt_action
set_wt () {
print -Pn "\e]0;%n@%m on %~\a"
}
add-zsh-hook -Uz precmd set_wt
+function osc7 {
+ local LC_ALL=C
+ export LC_ALL
+ setopt localoptions extendedglob
+ input=( ${(s::)PWD} )
+ uri=${(j::)input/(#b)([^A-Za-z0-9_.\!~*\'\(\)-\/])/%${(l:2::0:)$(([##16]#match))}}
+ print -n "\e]7;file://${HOSTNAME}${uri}\e\\"
+}
+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"
+ then
+ "$EDITOR" "$1"
+ 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~ '