source a file in .zshrc does not find the file - macos

I'm using zsh on Catalina and I have some problems with sourcing (dunno if that's the correct term) a file in my .zshrc file that has a white space in the path.
Basically what I'm trying to achieve is to have my personal zsh settings in iCloud so that it syncs between all my computers. There is a white space in the path to my iCloud directory that I can't change.
~/Library/Mobile Documents/com~apple~CloudDocs/
Escaping the wihte space does not work when I try it.
file='~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh'
source $file
Results in:
.zshrc:source:29: no such file or directory: ~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
It works fine when I manually do:
source ~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
Any ideas on how to solve this or I'm I back at manually load my files?

The quotes are ruining your day, and the excaped space doesn't make much sense either, because you are quoting the whole stuff anyway:
file='~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh'
This means that you need a directory with the name ~.
You could write it as
file=~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
which would substitute the tilde by your home directory. I personally would use double quotes and write it as:
file="$HOME/Library/Mobile Documents/com~apple~CloudDocs/file.sh"

Related

Running executable script from iCloud folder

I'm running an executable script from my iCloud folder. I get the following error
"ERROR: run_shell_command on /Users/username/Library/Mobile Documents/com~apple~CloudDocs... /bin/bash: /Users/username/Library/Mobile: No such file or directory"
which has to do with the space between "Mobile" and "Documents" in the iCloud path. How do you handle these cases. I'm sure there is an easy solution but I can't figure it out.
I've checked running the script in my local machine and it works. However, I would prefer to do this from the cloud to optimize space.
Thank you
Spaces are escaped with the \ character.
For example:
cd /Users/username/Library/Mobile\ Documents
You can also enclose the argument in quotes:
cd '/Users/username/Library/Mobile Documents'
This solves the space-in-path problem on iCloud Drive persistently:
# bash 5 will expand $HOME to your home dir path.
# Or, replace '$HOME' with /Users/<username>
cd ~
ln -s "$HOME/Library/Mobile\ Documents/com~apple~CloudDocs" icloud
cd ~/icloud
From ~/icloud I enjoy command line access. My bash autocomplete works. I can ignore the tildes and space. I use unix naming for the files and directories below ~/icloud, to make script access easier.
#cmartinezvil if you get tired of quoting paths every time, the symlink is handy. You can get the docs using info ln on MacOs.
Thanks go to #jl-peyret for this answer.
https://apple.stackexchange.com/questions/428604/how-to-make-icloud-drive-conveniently-available-to-the-shell/448685#448685

How to change $PATH variable in bash_profile in OSX?

I am trying to install a 3rd party library from GitHub through terminal. Before this installed Anaconda Python distribution on my system and that has modified my root directory of my terminal to;
Vinos-MBP:~ Vino$
So when try to navigate to a particular directory to install the said library using
cd /Users/Vino/<install location>
The terminal prints the following message;
-bash: cd: /Users/Vino/Documents/My: No such file or directory
I know this problem is because Python has modified my bash_profile startup file. I tried various online methods to fix this issue, but nothing actually works. Whenever I restart my terminal and navigate using cd, I get the same error. How do I reset $PATH to $HOME (like as before installing Anaconda), so that I can navigate to any folder on my system?
This is not a problem with $PATH or $HOME -- it looks to me like you have a space in the folder name, and aren't properly quoting/escaping it. If they aren't quoted or escaped, spaces are taken as separators between arguments (e.g. folder paths) rather than part of the path. If the folder you're trying to cd to is "/Users/Vino/Documents/My Installation Location", you could use any of these:
cd "/Users/Vino/Documents/My Installation Location"
cd '/Users/Vino/Documents/My Installation Location'
cd /Users/Vino/Documents/My\ Installation\ Location
cd ~/Documents/My\ Installation\ Location
cd ~/"Documents/My Installation Location" # Note that the ~/ part must not be quoted
There are a number of other characters that're perfectly legal to have in filenames that will cause trouble when used on the command line without quotes or escapes (including the quote and escape characters themselves!). One way to avoid trouble is to drag-and-drop an item from the Finder into the Terminal window, and it'll fill in a (properly escaped) path to that item.

MacOS Terminal go to a folder with spaces and parenthesis

I'm trying to configure Cyberduck to read the Bookmark files from my Dropbox folder.
This is usually accomplished by this command:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox/Cyberduck
Super easy!!
But... Dropbox has since changed and if you have a Pro Account the Dropbox folder is renamed "Dropbox (Personal)".
I've tried to do this:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox\ \(Personal\)/
And I get this error:
not parse: [...]/Dropbox (Personal)/Apps/Cyberduck/. Try single-quoting it.
I tried single quoting like this but same error:
defaults write ch.sudo.cyberduck application.support.path '~/Dropbox\ \(Personal\)/'
How can I solve this?
You can single quote escape your parentheses by wrapping them in a double quote:
Instead of: ln -s '/Users/username/Dropbox (Company Name)/' DropboxCompanyName
Do: ln -s "'/Users/username/Dropbox (Company Name)/'" DropboxCompanyName
Notice the double quotes added to /Users/username/Dropbox (Company Name)/
So I cannot find a way to do a "defaults write" to a path with parentheses, but I did this workaround and it seemed to work for me (in my case I needed to link to my enterprise Dropbox account):
cd to your home folder and create a symlink of the directory that has the parentheses:
ln -s '/Users/username/Dropbox (Company Name)/' DropboxCompanyName
At that point, I was able to do do a defaults write that wrote ~/DropboxCompanyName as part of the path and it worked just fine.
All that said, your personal folder already has a hidden symlink: "Dropbox" that's in the same directory and pointing to "Dropbox (Personal)", so you should be able to do you original command as such:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox/Cyberduck
… because the "Dropbox" part of the path should still lead to your personal folder. This both what I've observed locally (when viewing hidden files) and what Dropbox says on their site: https://www.dropbox.com/help/9031
I am assuming you are using Unix in Terminal.
I have set up a folder of the same name in my Public Folder to test as shown below.
Your current referencing to the folder would seem correct. Dragging the folder into the Terminal window current command line will automatically give you the correct referencing to that folder.
As an alternative I suggest putting the name of the folder in double quotation marks. Even though there are brackets in the name, there is no need to escape these characters in Unix in Terminal in this instance when using double quotation marks. This makes it easier to humanly type the correct reference.
To reference a folder in the image below, for example, the following referencing works for the cd (change directory command):
~/Public/"Dropbox (Personal)"
Hence I suggest try:
ch.sudo.cyberduck application.support.path ~/Public/"Dropbox (Personal)"
As for the rest of this command, I am not sure that ch is a valid Unix command. I do not yet have enough Unix experience to guide you from here.
you have to put "" in the whole address
more like this
ch.sudo.cyberduck application.support.path "~/Public/Dropbox (Personal)"

Git bash error reading vimrc

Problem: git bash can't read my .vimrc file, giving this error:
Error detected while processing /c/Users/Simon/.vimrc:
line 1:
E484: Can't open file D:Dropboxdotfilesvimvimrc.vim
My setup is atypical, although not too strange.
I have my vim directory and vimrc.vim file stored on Dropbox (D:\Dropbox\dotfiles\vim and D:\Dropbox\dotfiles\vim\vimrc.vim) so I can easily move the config and plugins between machines
In my home directory (C:\Users\Simon\) I have created a link to the vim directory on Dropbox and my .vimrc sources vimrc.vim from the Dropbox location (source D:\Dropbox\dotfiles\vim\vimrc.vim)
When I run gvim and vim from the start menu everything gets loaded fine and it all works. It doesn't work when using git bash though because it seems to remove the required backslashes from the file path. I assume this will also be a problem when trying to load things like color schemes and plugins, which are stored in the Dropbox .vim directory as well.
What is the correct fix for making git bash see the slashes in folder/file links in Windows?
So, it turns out that using the unix directory structure and forward slashes / in the source line:
source /d/Dropbox/dotfiles/vim/vimrc.vim
actually makes the situation worse because it breaks gvim as well as vim in bash and cmd. After OP played around with it, it turns out the fix is actually to just replace all backslashes with forward slashes in the original source line:
source D:\Dropbox\dotfiles\vim\vimrc.vim (original)
source D:/Dropbox/dotfiles/vim/vimrc.vim (working)
And everything seems to be OK now.

Copy file path to terminal without escape sequences in mac

I have a perl script that takes input file path from the terminal. So, while entering the file path, I can drag and drop the file to the terminal (Mac). If I have file paths like
/Users/San/abc(ev50)_xyz.tif,
then dragging and dropping the file will result in
/Users/San/abc\(ev50\)_xyz.tif
being pasted on the terminal. Is there a way to copy paste (drag and drop) the file path as is? I saw in some of the forums, they had mentioned about creating a service and so on. But, I want to know if there is an easy way to paste it as is.
Drag/drop enters the filename, with characters that might present problems to shell scripts escaped with backslashes (such as bash). Reading the filename directly, you of course do not have this problem. The solution is to remove the extra backslashes, e.g., as done in #Ether's answer to How can I unescape backslashes in a Perl string?.

Resources