I do not understand what you are doing there, and:
just gave this error.
zsh: ~/Home Data Cluster/Linux/Scripts/SSH-menu.sh: bad interpreter: ~/.zshrc: no such file or directory
That’s why I didn’t give you the output, because it’s best summarized by saying “no results”. And other permutations that I tried where even less interesting. Believe me, it is like drawing blood from a stone, because there is no blood. I am just trying to spare you your teeth.
Not sure what you mean by that, this never send anything to any function from one script to another (or at least I see no reason to).
What it does is run a command in shell that THEN is handled by zsh4humans.
If the goal is to interwine the 2 scripts into one (this makes zero sense to me, but I guess it’s doable) then a source is needed.
But I have constantly been questioning the reasoning for even trying to do that?
AGAIN. If you run a command in cli, and you use that exact command in a shell script, all it does is run that exact command, so just use that command in the menu, remove all sourcing and just run the command.
Please run this command in your cli and return the output again. I have a hard time believing a command that works in cli suddenly wont work in a script.
The script doesn’t even call those commands anymore. It now calls the aliases in the .ssh/config file. If I call an alias, it just logs me in with Z4H extrapolated, and the same happens if I call command like the one you have described. It all works, just not from the script.
The % means it’s run from zsh. I showed you a command that dumps the contents of a file to the terminal, so you can see it .
Then I sourced the file, to define the function in the current shell.
Then I ran it and showed the output.
Put the function in .zshrc (that’s what # ~/.zshrc was meant to mean), then source the file source ~/.zshrc in the current terminal. Then forget the script. Sorry I wasn’t very clear before.
That’s best summarised as “I got this error…”
@bedna
It’s not a command (ie an external program), it’s a function defined by z4h.
Makes total sense it doen’t like it, you source these in your script, ie running everything inside the script, because when sourcing those, the functions you mention also gets sourced. It makes perfect sense.
My final recommendation: I repeat, remove all sourcing in the script. Make a menu and hardcode the commands (that works in cli) in the cases.
This is what I suspect is happening when typing ssh in terminal. ssh is canged out by zsh4humans, the script runs and and calls other scripts OR sources stuff, including both .zshenv and .zshrc.
Since those files are already sourced in his menu script, some of the functions gets created inside there, so confusion erupts.
z4f probably needs to be set first f ex.
I haven’t actually read the files on the github, but this explanation makes total sense to me and explains the errors too.
That is why I keep saying remove the sourcing in the menu script and just issue the command.
Because the changed script in ssh might never run, since 2 config files are sourced.
Brother, I have tried it all a few times already. So many iterations changing shells, sources and commands … I really think my gut feeling is right from the original post, and I think we were maybe onto something sourcing the config files.
Right now, I have left it the way it was and just added the aliases from .ssh/config and that is what is giving me the best results. I just have to figure out the extrapolation. Maybe someone else finds the post and knows where the problem is, because I am out of ideas.
Right, that could be a possibility, but we already tried sourcing .zshenv and it didn’t do the trick. Tried one more time for good measure and it didn’t work.
For reference.
Unless changes has been made by you @Centaro , this is what those files contain.
.zshenv
# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md.
#
# Do not modify this file unless you know exactly what you are doing.
# It is strongly recommended to keep all shell customization and configuration
# (including exported environment variables such as PATH) in ~/.zshrc or in
# files sourced from ~/.zshrc. If you are certain that you must export some
# environment variables in ~/.zshenv, do it where indicated by comments below.
if [ -n "${ZSH_VERSION-}" ]; then
# If you are certain that you must export some environment variables
# in ~/.zshenv (see comments at the top!), do it here:
#
# export GOPATH=$HOME/go
#
# Do not change anything else in this file.
: ${ZDOTDIR:=~}
setopt no_global_rcs
[[ -o no_interactive && -z "${Z4H_BOOTSTRAPPING-}" ]] && return
setopt no_rcs
unset Z4H_BOOTSTRAPPING
fi
Z4H_URL="https://raw.githubusercontent.com/romkatv/zsh4humans/v5"
: "${Z4H:=${XDG_CACHE_HOME:-$HOME/.cache}/zsh4humans/v5}"
umask o-w
if [ ! -e "$Z4H"/z4h.zsh ]; then
mkdir -p -- "$Z4H" || return
>&2 printf '\033[33mz4h\033[0m: fetching \033[4mz4h.zsh\033[0m\n'
if command -v curl >/dev/null 2>&1; then
curl -fsSL -- "$Z4H_URL"/z4h.zsh >"$Z4H"/z4h.zsh.$$ || return
elif command -v wget >/dev/null 2>&1; then
wget -O- -- "$Z4H_URL"/z4h.zsh >"$Z4H"/z4h.zsh.$$ || return
else
>&2 printf '\033[33mz4h\033[0m: please install \033[32mcurl\033[0m or \033[32mwget\033[0m\n'
return 1
fi
mv -- "$Z4H"/z4h.zsh.$$ "$Z4H"/z4h.zsh || return
fi
. "$Z4H"/z4h.zsh || return
setopt rcs
.zshrc
# 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.
# Periodic auto-update on Zsh startup: 'ask' or 'no'.
# You can manually run `z4h update` to update everything.
zstyle ':z4h:' auto-update 'no'
# Ask whether to auto-update this often; has no effect if auto-update is 'no'.
zstyle ':z4h:' auto-update-days '28'
# Keyboard type: 'mac' or 'pc'.
zstyle ':z4h:bindkey' keyboard 'pc'
# Mark up shell's output with semantic information.
zstyle ':z4h:' term-shell-integration 'yes'
# Right-arrow key accepts one character ('partial-accept') from
# command autosuggestions or the whole thing ('accept')?
zstyle ':z4h:autosuggestions' forward-char 'accept'
# Recursively traverse directories when TAB-completing files.
zstyle ':z4h:fzf-complete' recurse-dirs 'no'
# Enable direnv to automatically source .envrc files.
zstyle ':z4h:direnv' enable 'no'
# Show "loading" and "unloading" notifications from direnv.
zstyle ':z4h:direnv:success' notify 'yes'
# Enable ('yes') or disable ('no') automatic teleportation of z4h over
# SSH when connecting to these hosts.
zstyle ':z4h:ssh:example-hostname1' enable 'yes'
zstyle ':z4h:ssh:*.example-hostname2' enable 'no'
# The default value if none of the overrides above match the hostname.
zstyle ':z4h:ssh:*' enable 'no'
# Send these files over to the remote host when connecting over SSH to the
# enabled hosts.
zstyle ':z4h:ssh:*' send-extra-files '~/.nanorc' '~/.env.zsh'
# Clone additional Git repositories from GitHub.
#
# This doesn't do anything apart from cloning the repository and keeping it
# up-to-date. Cloned files can be used after `z4h init`. This is just an
# example. If you don't plan to use Oh My Zsh, delete this line.
z4h install ohmyzsh/ohmyzsh || return
# Install or update core components (fzf, zsh-autosuggestions, etc.) and
# initialize Zsh. After this point console I/O is unavailable until Zsh
# is fully initialized. Everything that requires user interaction or can
# perform network I/O must be done above. Everything else is best done below.
z4h init || return
# Extend PATH.
path=(~/bin $path)
# Export environment variables.
export GPG_TTY=$TTY
# Source additional local files if they exist.
z4h source ~/.env.zsh
# Use additional Git repositories pulled in with `z4h install`.
#
# This is just an example that you should delete. It does nothing useful.
z4h source ohmyzsh/ohmyzsh/lib/diagnostics.zsh # source an individual file
z4h load ohmyzsh/ohmyzsh/plugins/emoji-clock # load a plugin
# Define key bindings.
z4h bindkey z4h-backward-kill-word Ctrl+Backspace Ctrl+H
z4h bindkey z4h-backward-kill-zword Ctrl+Alt+Backspace
z4h bindkey undo Ctrl+/ Shift+Tab # undo the last command line change
z4h bindkey redo Alt+/ # redo the last undone command line change
z4h bindkey z4h-cd-back Alt+Left # cd into the previous directory
z4h bindkey z4h-cd-forward Alt+Right # cd into the next directory
z4h bindkey z4h-cd-up Alt+Up # cd into the parent directory
z4h bindkey z4h-cd-down Alt+Down # cd into a child directory
# Autoload functions.
autoload -Uz zmv
# Define functions and completions.
function md() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" }
compdef _directories md
# Define named directories: ~w <=> Windows home directory on WSL.
[[ -z $z4h_win_home ]] || hash -d w=$z4h_win_home
# Define aliases.
alias tree='tree -a -I .git'
# Add flags to existing aliases.
alias ls="${aliases[ls]:-ls} -A"
# Set shell options: http://zsh.sourceforge.net/Doc/Release/Options.html.
setopt glob_dots # no special treatment for file names with a leading dot
setopt no_auto_menu # require an extra TAB press to open the completion menu
that is my .zshenv and in .zshrc I just moved this section to the top and added my sources with the if statements.
# Source additional local files if they exist.
z4h source ~/.env.zsh
#Source zsh-configuration
if [[ -e ~/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-extras.zshrc ]]; then
source ~/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-extras.zshrc
fi
if [[ -e ~/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-p10k.zsh ]]; then
source ~/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/custom-p10k.zsh
fi
and here I added the extra files at the end.
# Send these files over to the remote host when connecting over SSH to the
# enabled hosts.
zstyle ':z4h:ssh:*' send-extra-files '~/.nanorc' '~/.env.zsh' '~/Home\ Data\ Cluster/Linux/Custom\ ZSH/Deploy/*'