How do I make zsh autocompletion remove trailing slash it returns? - autocomplete

I have a custom script that I pass an argument into that will create a directory in a specific folder and then cd to it, unless it already exists, then it just cd to it.
I added a zsh autocompletion that way if I want to use the command to just jump to a directory in that folder I can autocomplete the target folder and get there in less keystrokes. The only issue with my zsh autocomplete is that it leaves the tailing directory slash after the autocomplete. Is there any way to tell zsh to only return the name of the directory and leave the / off? The docs are long winded and my searching has not turned up anything useful.
Here is my zsh autocomplete
compdef '_path_files -W /home/me/dir1/dir2/folder -/ && return 0 || return 1' mycommand

Related

How to get vim to list the PIDs of selected files that are presently being edited, avoiding recovery mode, and not list all the other files

The vim manual page contains two similar -r type commands. I'll give more background below, this question is really how to invoke the first type of -r to list the swap files, but avoid the second -r that invokes recovery
-r List swap files, with information about using them for re‐
covery.
-r {file} Recovery mode. The swap file is used to recover a crashed
editing session. The swap file is a file with the same
filename as the text file with ".swp" appended. See ":help
recovery".
The -r without filename (the first -r above ) reports on the swap files of other files too, including ones in other directories
Background:
I'm trying to have vim report the swap files of a specific file (mostly to determine if vim still editing the file). If the file is being edited ( in another window, either on linux or cygwin ) I can 'raise' that window up to the top with "\e[2t\e[1t" as I have successfully be able to do thanks to Bring Window to Front
Vim has multiple swap file names, and multiple directories that it could put a file, so I want to ask vim, please tell me the name of the swap files that are currently in use for a given file, and if there is a current vim process on the file. Unfortunately, sometimes vim will open a command file in recovery mode in unexpected ways.
I'm invoking vim like this vim -r -c :q file, well actually, I'm invoking it from script, since I want vim to see something more like a terminal, then I look at the output file, so it's more like script -q -c "vim -r -c :q foo" fooscript, then I look in the fooscript file for messages like /Note: process STILL RUNNING: (\d+)/
It is beginning to look like I need to use vim -r without a file name, and parse the output of the -r report, and that there isn't a way to get the report pre-filtered to a single file in question.
after switching my focus to just vim -r, and
Knowing that vim will try to put the swap file into the same directory as the file it's editing ( thanks to #romainl for the pointer to :help swap-file )
observing that vim -r reports on the files in the current directory first,
observing that the file name associated with the swap file is reported before the process id of the vim process, and
observing that vim appends (STILL RUNNING) if it finds the active process
I changed the current directory appropriately and ran this code after plugging in the name of the file-to-search-for
perl -lne '
last if /^\s+In directory/;
undef $f if /^\d+/;
$f = $1 if /^\s+file name:\s+(.*)\s*$/;
if ( $f =~ m#/file-to-search-for# && /^\s+ process ID:\s(\d+).*?STILL RUNNING/ ) {
print $1;
$pid //= $1;
}
END { exit !$pid; } '
The pid of the running vim process is printed, and the exit status is zero when the appropiate swap file is found, and non-zero if the file was not being edited

Terminal errors - "zsh: command not found" when trying any command

I was adding a path to my zshrc file earlier on and after saving the file and re-opening up my Terminal, I've found that I am unable to use any command what so ever.
The error I get back on any command I type in is this:
No matter what I try typing in I get this error, I have not been able to reopen my zsh file either to remove the paths I added as there is obviously an issue with them.
Can anyone advise the best thing to do to fix this without having to reboot my entire OS?
Many thanks in advance
Use the macOS Finder to rename the .zshrc file to .Xzshrc or something.
.zshrc is in your home directory. One way to navigate to that directory is to enter Shift+Command+H.
Since the filename starts with ., it's a hidden file. To get Finder to display hidden files, enter Shift+Command+..
Now you can restart Terminal, and rebuild your .zshrc file, copying pieces from .Xzshrc as needed. The error is probably in a path assignment.
In NVM repository shows how to add source lines to correct profile file:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Source: nvm

Windows Powershell Basic Questions - new user

When trying to open a file with text editor VIM, I am unable to open the file unless VIM (shortcut) is in my current working directory. As an example, I am able to write start firefox to open a firefox window. However, start vim C:\filepath\filename.txt does not work unless a vim shortcut is in my current directory. How do I get around this?
Also, is there a way to have a program execute a file in the current working directory without having to reference the entire file path? For example instead of Start-Process vim C:\Users\User\Desktop\File\file.txt is there an available path shortcut like Start-Process vim ~\file.txt with ~ representing the current working directory?
The OS need to determine the full path of the exe, no matter what.
There's 2 ways that it will happen.
You're calling the executable from it's working directory
The executable location is in the Windows environment variable.
You can view the PATH variable content through this simple statement
$env:Path -split ';' | sort
You sill see that the Firefox path is listed there, but not the one from VIM.
That's why the former can be started by it's executable name and the latter require the full path.
You need to add VIM directory to your PATH variable if you want to be able to call it just by typing vim
Otherwise, if you have restricted access or don't want to edit that variable, you can also set a $vim variable, then invoke it whenever you want to call the executable.
Regarding the second part of your question
Powershell use the dot as a reference to the current directory .\file.txt.
You can also just specify the filename without anything else file.txt.
Both backslash \ & slash / work for filepath so .\file.txt and ./file.txt are both valid ways to reference the file.
Use ..\ to reference the parent directory (e.g. ..\file.txt)
$Vim = "c:\Path\To\Vim.exe"
& $vim "file.txt"
& $vim ".\file.txt"
#Forward slash also work for paths
& $vim "./file.txt"

Oh-my-zsh aliases do not autocomplete

I am a bit out of my wits researching this... and I just have to ask.
I have oh-my-zsh on my Mavericks machine and have everything updated. I also have Xcode and Brew. All updated. According to this page: https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet am I not supposed to just type, say: "g" [tab] and get "git"? or type "md" [tab] and get "mkdir -p"? Right now I just get a list of options I can tab through (or arrow through)... I thought it would autocomplete. What am I missing?
I have a feeling it might be related to my $PATH but that is where I also get confused... where should it point to?
I greatly appreciate and enlightenment.
# Path to your oh-my-zsh configuration.
#ZSH=$HOME/.oh-my-zsh
export ZSH=$HOME/.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"
ZSH_THEME="agnoster"
# Set to this to use case-sensitive completion
# CASE_SENSITIVE="true"
# Comment this out to disable weekly auto-update checks
# DISABLE_AUTO_UPDATE="true"
# Uncomment following line if you want to disable colors in ls
# DISABLE_LS_COLORS="true"
# Uncomment following line if you want to disable autosetting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment following line if you want red dots to be displayed while waiting for completion
COMPLETION_WAITING_DOTS="true"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git textmate sublime zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
#export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/$
#export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/local/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
zstyle ':completion:*' list-prompt ''
zstyle ':completion:*' select-prompt ''
autoload -Uz compinit
compinit
Aliases are essentially just short names for commands. Before executing a command zsh internally replaces aliases by their values. But by default aliases are not expanded when using completion (Tab), they are handled just like any other command.
For example:
alias ll='ls -l'
alias la='ls -al'
If you now type lTab, zsh will present you every command starting with an l, including the aliases ll and la. If you type llTab it will probably just add an space after ll (assuming there are no other commands starting with ll).
When you run ll somedir it does the exact same thing as ls -l somedir. You can even add other options of ls: ll -t somedir runs ls -l -t somedir.
That being said, if you want to expand aliases when typing Tab, zsh can do so.
There are two ways:
You can call the _expand_alias widget. In emacs mode (bindkey -e) this is bound to ^Xa (press Control+X then A).
You can add _expand_alias to the completer style. It seems that oh-my-zsh does not change this style from its default value, so adding
zstyle ':completion:*' completer _expand_alias _complete _ignored
to your ~/.zshrc should work.
(To be save you can print the current setting with zstyle -L ':completion:*' completer, _expand_alias has to come before _complete)
If you now type llTab, zsh will replace it with ls -l immediatelly.
Note: in both cases the cursor has to be in or just after the alias for the replacement to happen. This also means you have to type the whole alias or backspace if automatically completed (_completer adds a space after successful completion)

Prevent vim :make from changing the current working directory?

Synopsis:
When calling vim's make command, it changes the current working directory (cwd) to the directory of the current file. It then runs the makeprg from there. I want to prevent the make command from changing the cwd, and instead call the makeprg from the directory of the parent vim instance
Example:
I have the following standard perl project hierarchy
project/
lib/
My/
Module/
Foo.pm
My PERL5LIB is set to
PERL5LIB=':lib'
In my .vimrc I have
compiler perl
set makeprg=perl\ -c\ %
I edit my module using vim from the root project level:
/path/to/project$ vim lib/My/Module/Foo.pm
In vim :pwd works as expected:
:pwd
"/path/to/project"
Also calling !perl -c works as expected, finds my project lib, and displays the result in a shell window:
:!perl-c %
OUTPUT:
perl -c lib/My/Module/Foo.pm
lib/My/Module/Foo.pm Syntax ok
However :make returns an error
:make
"Can't open perl script lib/My/Module/Foo.pm : No such file or directory"
Setting makeprg to pwd shows the problem
:set makeprg=pwd
:make
"/path/to/project/lib/My/Module"
So before make runs makeprg it is changing to the directory of the current file, which is why perl can't find 'lib/.../Foo.pm' there.
Is there any way to prevent make from doing this?
If Vim's :make command is changing the current working directory, and autochdir is not set, a plugin may have added an autocommand to the QuickFixCmdPre set. One plugin that does this is eclim, which calls the QuickFixLocalChangeDirectory() function if g:EclimMakeLCD is set to 1.
Use :au to find all the autocommands in your current configuration, paying particular attention to entries for QuickFixCmdPre and make.