Unfortunately, I am not at all familiar with set, unset and functions substituting command paths. Also, I am not that familiar with Z4H or ZSH customization. And for now, I would rather not unset the function, just in case it breaks the current functionality I enjoy.
Also, I know that scripting in bash is more portable, but I am trying to make all of my environments run ZSH, so I won’t care until I find myself in a pinch.
It would only be temporary, unless you found the definition for the function and removed it. Absolutely worst case, you can redefine the function yourself, you already have a copy in the first post.
However there are other options:
I found a new command, this will ignore the function.
None of these options solves the issue. I think the function is what is actually producing the desirable results, that’s why I was trying to call it in my script.
Ah, I was thinking it was getting in the way .The script you showed didn’t have that function, and you said you’d tried to substitute ssh for the function (but you meant you’d tried to substitute the function for ssh). Clearly I focused on that and forgot about, amongst other things, the 2nd line of your post.
The files are there, but I get the following errors.
~/.zshenv:source:3: no such file or directory: ~/.zshenv
~/.zshrc:source:4: no such file or directory: ~/.zshrc
I have also tried with quotation marks for the paths, full paths and calling the sources within the “then” statements, but to no avail.
This is how my .zshrc file starts:
# Source additional local files if they exist.
z4h source ~/.env.zsh
#Source zsh-configuration
if [[ -e /path/custom-extras.zshrc ]]; then
source /path/custom-extras.zshrc
fi
if [[ -e /path/custom-p10k.zsh ]]; then
source /path/custom-p10k.zsh
fi
With the risk of being a complete idiot here. Where do you call the ssh function?
The cases runs the ssh command in your terminal (connects), not the function, if you want to call the function you have to ssh 'a@a -p 224' and then fetch that with $* inside the function.
But I have no idea how it will react, since there is an ssh command in shell…
So, why call the function ssh exactly? That makes things confusing. Call it fex ssh_function instead, that makes it way safer to call it since it does not have the same name as a program. ssh_function 'a@a -p 224'
And on top, if you hardcode the case:s, why not run the z4h command directly there? Why the function?
@dmt, I already tried with the full paths for the directories in the source commands and it didn’t work. I am not familiar with source, but that is very strange behavior.
# Personal Zsh configuration file. It is strongly recommended to keep all
# shell customization and configuration (including exported environment
# variables such as PATH) in this file or in files sourced from it.
#
# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md.
# Source additional local files if they exist.
z4h source ~/.env.zsh
#Source zsh-configuration
if [[ -e /home/username/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-extras.zshrc ]]; then
source /home/username/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-extras.zshrc
fi
if [[ -e /home/username/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-p10k.zsh ]]; then
source /home/username/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-p10k.zsh
fi
I don’t think the paths are the problem. They work when I ssh into machines any other way.
The file for “custom-p10k” is very generic, I only changed a few powerline parameters.
My other script is just aliases and such.
########################################
# ALIASES
########################################
####################
#PROGRAMS
####################
alias m='micro'
####################
#NAVIGATION
####################
alias hd='cd ~'
alias ud='cd ..'
alias pd='pushd'
alias d1='pushd +1'
alias d2='pushd +2'
alias d3='pushd +3'
alias d4='pushd +4'
alias d5='pushd +5'
if [[ @USER == root ]]
then
alias sd="dirs -v | awk 'NR>1' | awk '!seen[$2]++'"
else
alias sd="dirs -v | awk 'NR>1'"
fi
alias ppd='popd'
####################
#COMMANDS
####################
alias ll='ls -lh'
########################################
# ENVIRONMENT
########################################
# Editor
export EDITOR=/usr/bin/micro
I don’t think they are the problem, because again, the export works when I ssh into machines any other way.
A source is just you pulling the contents of another file right into the file you run the command from.
And I think, overwrite if the same text exists? Correct me if I’m wrong @dmt
Try removing z4h to begin with.
Of if you want to use it as a variable, add a =. xD
I am not familiar with z4h to be honest so I most likely wont be much help anyway.
I thought you wanted a simple script with a menu, and depending on the choice a command line was selected and ran.
So, I don’t know why I didn’t find it before, I think I looked, but Z4H also has a function:
z4h () {
if (( ${+functions[-z4h-cmd-${1-}]} ))
then
-z4h-cmd-"$1" "${@:2}"
else
-z4h-cmd-help >&2
return 1
fi
}
I just don’t understand how these functions work. They are very intricate.
What throws me off is that when I call “ssh” from the terminal I am clearly calling that function, and when the script calls it, it is calling the regular command like it where from “/usr/bin/ssh”, no matter whether the script starts in #!/usr/bin/bash or #!/usr/bin/zsh and also regardless of having the full path to ssh “/usr/bin/ssh” or just “ssh”. Also, the storage cluster works fine. All the files are there.
It passes the contents of the file to the Tcl interpreter. If you source a file from the terminal it’ll run it in the current shell (with the same environment, ie vars etc), if you run the script directly it’ll run in a child shell with a different environment.
When sourced in a script, it will presumably run the script in the same shell as the parent script.