Why tmuxinator zsh complete file is not work? - zsh

According to the hint, I download the file
https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh
into /usr/local/share/zsh/site-functions/_tmuxinator(file path), but the autocompletion not work.
Then I source the file like below in ~/.zshrc, it is also not work.
. /usr/local/share/zsh/site-functions/_tmuxinator
My config environments are:
zsh: zsh 5.8 (x86_64-suse-linux-gnu)
tmuxinator: tmuxinator 2.0.1
And I use oh-my-zsh as my zsh environment and rbenv to install tmuxinator.
The fpath environment variable in my system is:
/home/run/.oh-my-zsh/plugins/git /home/run/.oh-my-zsh/functions /home/run/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh//functions/Calendar /usr/share/zsh//functions/Chpwd /usr/share/zsh//functions/Completion /usr/share/zsh//functions/Completion/Base /usr/share/zsh//functions/Completion/Linux /usr/share/zsh//functions/Completion/Unix /usr/share/zsh//functions/Completion/X /usr/share/zsh//functions/Completion/Zsh /usr/share/zsh//functions/Completion/openSUSE /usr/share/zsh//functions/Exceptions /usr/share/zsh//functions/MIME /usr/share/zsh//functions/Math /usr/share/zsh//functions/Misc /usr/share/zsh//functions/Newuser /usr/share/zsh//functions/Prompts /usr/share/zsh//functions/TCP /usr/share/zsh//functions/VCS_Info /usr/share/zsh//functions/VCS_Info/Backends /usr/share/zsh//functions/Zftp /usr/share/zsh//functions/Zle /etc/zsh_completion.d
which includes the directory /usr/local/share/zsh/site-functions.

You may have to force rebuild zcompdump:
rm -f ~/.zcompdump; compinit

Related

Rscript to use renv environment

How do I execute a command using RScript myfile.R so that it uses the renv environment of the project/directory it's in, NOT my default environment?
There are a couple ways:
Ensure your working directory is set to the root of your renv project, and that the renv project's auto-loader is active. (You can set up the auto-loader by calling renv::activate() from R in that project.)
In your script, explicitly call renv::load("/path/to/project") to load the requested project.
If neither of these methods suffice, please file an issue at https://github.com/rstudio/renv/issues.
I recently had a similar problem but the answer by #kevin-ushey was insufficient. Here's the background. I need to be able to run Rscript from any directory (Because I had several statistical models which were to be called from a Docker file, forcing a Docker file to have WORKDIR many times is just too cumbersome when you have long files with several Rscript calls. Moreover, some of these models are called several times in different bash files, making it cumbersome to cd to the directory before every Rscript call). We needed something akin to conda activate where any Rscript call would just use the activated 'renv environment' by default, regardless of what your working directory is. Here's a dummy example:
Install renv with install.packages('renv').
Create dummy folder with a dummy script containing the beepr library (just for the sake of the example) and initialize the renv environment:
mkdir ~/renv_test/
cd ~/renv_test/
echo "library(beepr); print('success')" >> test.R
Rscript -e "renv::init()"
Create a Docker image with the code below:
FROM rocker/r-base
ENV PROJ_ROOT='/usr/local/src/renv_test'
ENV RENV_DIR='/usr/local/.renv/'
COPY . $PROJ_ROOT
# Copy the projects renv infrastructure to RENV_DIR and remove all traces of renv from PROJ_ROOT
RUN mkdir -p $RENV_DIR/renv/ && \
cp $PROJ_ROOT/renv.lock $RENV_DIR && \
cp $PROJ_ROOT/renv/activate.R $RENV_DIR/renv/ && \
echo "source('renv/activate.R')" >> $RENV_DIR/.Rprofile && \
cd $RENV_DIR && \
Rscript -e "renv::restore()" && \
cd $PROJ_ROOT && Rscript -e "renv::deactivate()" && \
rm -rf renv/ renv.lock
# Set RENV_DIR's restore library as the default library
RUN echo $(cd $RENV_DIR && Rscript -e "cat(paste0('R_LIBS=', renv::paths\$library()), sep = '\n')") >> $HOME/.Renviron
# Run any script from any directory as if you had 'renv activated'
CMD Rscript $PROJ_ROOT/test.R
Here's a summary of the approach:
Copy the project to the docker image
Copy the renv infrastructure to a separate folder (here ~/.renv/) and restore the project there.
Eliminate all traces of renv from the project folder (this is so we don't mess up the path of the library if for some reason we execute a script from the root of this project).
Edit .Renviron so that it contains the restored library path in ~/.renv as the default library. This ensures that any new R session will use that library as the first option.
Execute any R scripts located in the project folder without having to cd or WORKDIR (docker) to the project folder.
If you build and run the previous Docker image, you should get a success statement even though we never cd to the project folder:
docker build -t renv_test .
docker run renv_test
[1] "success"
I believe a simpler way than the above answers:
Rscript -e 'renv::run("/path/to/myscript.R")'
It will pick up the renv environment from the base path. You can also specify the environment using the project parameter.

How can I save the path to a frequently used directory in UNIX?

Is there a way to save the path to a frequently used directory in UNIX, so instead of having to manually cd /path/to/directory I can just enter a shortcut cd myFavoritePath ??
Define your favorite directories in CDPATH environment variable. It's a colon-separated list of search paths available to the cd command. You should specify not a directory you want to switch but parent directory.
Here is brief info about it: http://docstore.mik.ua/orelly/unix/upt/ch14_05.htm
For example you have three directories you work with frequently:
/home/user/scripts/favorite/
/var/log/
/var/lib/
add to your ~/.bash_profile (or another shell profile file you use) the next line:
export CDPATH=.:/home/user/scripts:/var
In the example below I just redefine CDPATH in shell for the current session
[user#server lib]$ CDPATH=.:/var:/home/user/scripts
[user#server lib]$ cd log
/var/log
[user#server log]$ cd lib
/var/lib
[user#server lib]$ cd favorite
/home/user/scripts/favorite
If you want use tab while execute cd you can install bash-completion http://bash-completion.alioth.debian.org/ but it's optional
Also do not forget cd - command for quick switching to previous working dir
You can always add the directory path in ~/.bashrc
vi ~/.bashrc
export FAV_DIR1=''
The variables in .bashrc load into the environment on new session. So make sure to reboot.
Then you can visit the directory by something like:
cd $FAV_DIR1

How to specify a custom path for my .zshrc file?

I'm trying to move .zshrc to a folder where I keep this kind of files synced with Github.
But now whenever I start a zsh session it doesn't use that config file.
Assuming I changed the file to ~/.dotfiles how can I add ~/.dotfiles/.zshrc to the PATH(?!) to make zsh start with that config?
Doing source ~./dotfiles/.zshrc only works for that session. Doesn't work anymore if I close the terminal.
You can symlink:
ln -s /path/to/original /path/to/symlink
For the zshrc you can do something like:
ln -s ~/.dotiles/.zshrc ~/.zshrc
One alternative to a symlink is to put this in ~/.zshenv:
ZDOTDIR=~/.dotfiles
If you want .zshenv in ~/.dotfiles as well, you can look into setting ZDOTDIR in one of the global configuration files (/etc/zshenv is a good choice).
Alternatively, you can do what I do and use GNU Stow. I've got my dotfiles in a repository, one subdirectory per category, like so:
dotfilerepo/zsh/.zshrc
dotfilerepo/zsh/.zlogin
dotfilerepo/git/.gitconfig
dotfilerepo/vim/.vimrc
then I can cd into repo and do stow zsh and it'll create a symlink from ~/.zshrc to repo/zsh/.zshrc, another from zsh/.zlogin to ~/.zlogin. stow vim to create symlinks from the vim subdirectory to ~, etc.
I've got a script, install-linkfarm, that does all the stow commands so when I move onto a new machine, I clone my repo, cd to it and run install-linkfarm and am good to go.
You can put this in ~/.zshrc, even as its entire contents:
if [ -r ~/.dotfiles/.zshrc ]; then
source ~/.dotfiles/.zshrc
fi
Please use the export command mentioned below to solve your problem.
export ZDOTDIR=$HOME/.dotfiles
In Linux, you can check if your zsh is loading /etc/zsh/zshrc, and edit it.
If that's the case, redirect this to your custom script by adding:
sh $HOME/.dotfiles/zshrc
Here is an interesting hack that doesn't require you to use sym-links.
In your .xsession, (or .*wmrc) have the following:
xterm -e 'zsh -c ". ~/.dotfiles/.zshrc; zsh"'.
instead of just:
xterm
Make sure to put the -e at the end after all of your other xterm options.

ZSH and Oh-My-Zsh local environment mapping?

I used Bash Shell for a long time and recently switched to ZSH because of the greatness of the project O-My-Zsh.
I have no problems how to use the zsh but setuping the local environment. I am currently using the dotfiles structure from Peepcode screencast, illustrate file-tree below:
Map .bash_profile to .zshrc file, map .zshrc file to the ~/bin/dotfile/zshrc file, zshrc file just load 3 files which is environment, alias, config. ( Those 3 files are the logic separation of the .zshrc file )
That is my setup. It is currently working the way it should. I could use alias which I set in alias file, etc.
Here is my question, the project O-My-Zsh needs the config file like loading the .oh-my-zsh folder and .oh-my-zsh.sh files. It is working if I put .oh-my-zsh config setting in the ~/.zshrc file. Since I mapped .zshrc to another place, how could I still refer to source the O-My-Zsh themes, plugins, settings? How should I source the ~/.oh-my-zsh folder in the clean way?
I think I understand your question, and my current setup may be similar:
In an effort to make setup and sync between various machines, I have moved all of my dotfiles to Dropbox (in a folder called .zsh). A symlink connects Dropbox/.zsh/.zshrc to ~/.zshrc, and Dropbox/.zsh/.zshrc sources all of my various config files, like so:
# Set so that all other sourced files can be found.
export ZDOTDIR="$HOME/Dropbox/.zsh"
source $ZDOTDIR/checks.zsh
# source $ZDOTDIR/colors.zsh
source $ZDOTDIR/exports.zsh
source $ZDOTDIR/oh-my-zsh_opts.zsh
source $ZDOTDIR/setopt.zsh
source $ZDOTDIR/pyopts.zsh
source $ZDOTDIR/prompt.zsh
source $ZDOTDIR/completion.zsh
source $ZDOTDIR/aliases.zsh
source $ZDOTDIR/bindkeys.zsh
source $ZDOTDIR/functions.zsh
# source $ZDOTDIR/zsh_hooks.zsh
Similarly, $ZDOTDIR/oh-my-zsh_opts.zsh defines all of my Oh-my-zsh options:
# Path to your oh-my-zsh configuration.
ZSH=$ZDOTDIR/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# ZSH_THEME="af-magic"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(battery colored-man colorize cp extract frontend git pip python pyenv\
virtualenv)
if [[ $IS_MAC -eq 1 ]]; then
plugins=($plugins brew brew-cask osx textmate)
fi
if [[ $IS_LINUX -eq 1 ]]; then
plugins=($plugins)
fi
if [[ $HAS_APT -eq 1 ]]; then
plugins=($plugins debian)
fi
if [[ $HAS_YUM -eq 1 ]]; then
plugins=($plugins yum)
fi
source $ZSH/oh-my-zsh.sh

zsh auto completion in home dir

I used for years in openSuSE the:
#compdef w
_files -W ~/work -/
function to auto-complete the directory names in my ~/work dir.
It does not work in Ubuntu zsh -v 4.3.11, when I hit TAB after w I got directories from my home directory.
What's different in Ubuntu?
Nevermind I found cdpath variable. I added in my config file
cdpath=( /usr ~ ~/work )
and it works :) Just cd somechar Tab. No more compdef functions.

Resources