Change to dir only if not already in the dir

This commit is contained in:
Jeremy Gardais 2023-08-01 14:16:00 +02:00
parent e18e6efdbc
commit c39e41bc7f
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 13 additions and 7 deletions

20
zshrc
View File

@ -2194,7 +2194,7 @@ cf() {
# Display the 50 first lines of the selected file with bat (batcat) # Display the 50 first lines of the selected file with bat (batcat)
# Move to the directory of the selected file # Move to the directory of the selected file
# Open the selected file with vi # Open the selected file with vi
v() { function v() {
local files local files
local dir local dir
local file local file
@ -2213,7 +2213,8 @@ v() {
if [[ -n "${files}" ]] if [[ -n "${files}" ]]
then then
dir=$(dirname "${files}") dir=$(dirname "${files}")
cd -- "${dir}" ### Change directory only if not already in the expected dir
test $(realpath "${dir}") != $(realpath .) && cd -- "${dir}"
file=$(basename "${files}") file=$(basename "${files}")
vi -- "${file}" vi -- "${file}"
fi fi
@ -2246,7 +2247,8 @@ pdf() {
if [[ -n $files ]] if [[ -n $files ]]
then then
dir=$(dirname "${files}") dir=$(dirname "${files}")
cd -- "${dir}" ### Change directory only if not already in the expected dir
test $(realpath "${dir}") != $(realpath .) && cd -- "${dir}"
file=$(basename "${files}") file=$(basename "${files}")
"${PDF_VIEWER}" -- "${file}" "${PDF_VIEWER}" -- "${file}"
fi fi
@ -2357,7 +2359,8 @@ odt() {
if [[ -n $files ]] if [[ -n $files ]]
then then
dir=$(dirname "${files}") dir=$(dirname "${files}")
cd -- "${dir}" ### Change directory only if not already in the expected dir
test $(realpath "${dir}") != $(realpath .) && cd -- "${dir}"
file=$(basename "${files}") file=$(basename "${files}")
command libreoffice --writer "${file}" & command libreoffice --writer "${file}" &
fi fi
@ -2387,7 +2390,8 @@ ods() {
if [[ -n $files ]] if [[ -n $files ]]
then then
dir=$(dirname "${files}") dir=$(dirname "${files}")
cd -- "${dir}" ### Change directory only if not already in the expected dir
test $(realpath "${dir}") != $(realpath .) && cd -- "${dir}"
file=$(basename "${files}") file=$(basename "${files}")
command libreoffice --calc "${file}" & command libreoffice --calc "${file}" &
fi fi
@ -2417,7 +2421,8 @@ odp() {
if [[ -n $files ]] if [[ -n $files ]]
then then
dir=$(dirname "${files}") dir=$(dirname "${files}")
cd -- "${dir}" ### Change directory only if not already in the expected dir
test $(realpath "${dir}") != $(realpath .) && cd -- "${dir}"
file=$(basename "${files}") file=$(basename "${files}")
command libreoffice --impress "${file}" & command libreoffice --impress "${file}" &
fi fi
@ -2448,7 +2453,8 @@ fopen() {
if [[ -n $files ]] if [[ -n $files ]]
then then
dir=$(dirname "${files}") dir=$(dirname "${files}")
cd -- "${dir}" ### Change directory only if not already in the expected dir
test $(realpath "${dir}") != $(realpath .) && cd -- "${dir}"
file=$(basename "${files}") file=$(basename "${files}")
command xdg-open "${file}" & command xdg-open "${file}" &
fi fi