Can't get CtrlP to set working dir as root folder - vim

Im working on project that is in fact composed of several subproject, under a common git repository:
Project
- Sub Project A
- Sub Project B
- ...
I never work on the main folder, and always start from one of the sub projects, the problem is no matter what I try CtrlP always does the search starting from the main folder where the repo is.
I've tried a few settings from the project repo but no matter, such as bellow, but still can't get it to make any effect.
let g:ctrlp_working_path_mode = 'ca'
Any tips please?

Looking at the CtrlP docs suggests that you have three options:
Disable CtrlP's working directory searching: let g:ctrlp_working_path_mode = ''. It will then only search under Vim's current working directory, so just :cd to one of your sub projects' directories.
Ignore the sub project directories that you are not interested in: let g:ctrlp_custom_ignore = { 'dir': '\v[\/]Sub Project [AB]$' } (untested).
Add Sub Project A, Sub Project B, etc. as root markers: let g:ctrlp_root_markers = ['Sub Project A', 'Sub Project B']. This should stop CtrlP from traversing up beyond those sub directories.
I would suggest the first option since the others are a bit too hacky for my taste. The last option also didn't work for me in a quick test.

If you're used to CtrlP starting in your current working directory, and it suddenly seems to have stopped, it's probably a side effect of g:ctrlp_working_path_mode that is a bit unintuitive: it searches up the directory tree until it finds a source control root (like a .git folder), and treats that as the top level directory.
I'm used to it always being the top level of my current project, so when I started a new project, and it was using my home directory as the root, I was confused. It's because I hadn't yet initialized Git for the new project, so the first .git directory it found was in my home directory.
Initializing a Git repo for the new project made it behave as expected.
Here's the relevant section of the plugin help:
'g:ctrlp_working_path_mode'
When starting up, CtrlP sets its local working directory according to this
variable:
let g:ctrlp_working_path_mode = 'ra'
c - the directory of the current file.
a - like "c", but only applies when the current working directory outside of
CtrlP isn't a direct ancestor of the directory of the current file.
r - the nearest ancestor that contains one of these directories or files:
.git .hg .svn .bzr _darcs
w - begin finding a root from the current working directory outside of CtrlP
instead of from the directory of the current file (default). Only applies
when "r" is also present.
0 or <empty> - disable this feature.
Note #1: if "a" or "c" is included with "r", use the behavior of "a" or "c" (as
a fallback) when a root can't be found.
Note #2: you can use a b:var to set this option on a per buffer basis.

Related

Node creating file 1 level up from the current path

I was using path.resolve but this command created a monster folder that can't be deleted called lib..
path.resolve(__dirname + "../assets/pic/" + `${fileName}.png`)
Question 1
What is the propper usage to create a folder 1 level up from the current path?
Question 2
How to remove the lib../assets/pic folder? Deleting the entire project or using git reset --hard, git stash doesn't work because Windows 10 says the folder doesn't exist.
Answer to Question 1:
tl;dr
const fs = require('fs')
const folderName1DirUp = '../SomeFolder'
try {
if (!fs.existsSync(folderName1DirUp)){
fs.mkdirSync(folderName1DirUp)
}
} catch (err) {
console.error(err)
}
The back story:
Two ways to reference the current folder in a Node.js script. You can use ./ or __dirname. Note in addition to ./ you can also use ../ which points to the parent folder.
The difference between the two.
__dirname in a Node script will return the path of the folder where the current JavaScript file resides.
./ will give you the current working directory (and ../ the parent). For ./ a call to process.cwd(). returns the same thing.
Initially the current working directory is the path of the folder where you ran the node command, but during the execution of your script it can change by calling process.chdir(...).
There is one place where ./ refers to the current file path which is in a require(...) call. There the ./, for convenience, refers to the JavaScript file path which lets you import other modules based on the folder structure.
Thus the call to fs.mkdirSync('../SomeFolder') with the given folder name makes a folder one level up from the current working directory.
Answer to Question 2:
From a PowerShell prompt Remove-Item './../Folder1UpToDelete' -Force The ./ is for the current folder. The ../ is for one folder up from the current. Finally the Folder1UpToDelete is the one folder up from the current that you want to delete. The -Force makes sure to delete all sub-folders/files under the folder you want deleted including hidden and/or read-only files.
To answer the first question, to create a path 1 level up, you can use path.join():
path.join(__dirname, "../assets/pics", `${fileName}.png`);
For the second question, if deleting it through the explorer doesn't work, you can try:
fs.rmdirSync("E:/path/to/broken/folder..");
Using Git Bash and running
cd /c/path/to/broken/
rmdir folder..

Linux Command to Convert an Absolute Path to a Current Existing Relative Path

I already have the relative path: /home/Folder1/Folder2 which its original absolute path is /home/user1/Folder1/Folder2. And I have several scripts that are using /home/Folder1/Folder2. Now, I need to delete user1 so I created user2 with the same structure of user1 so now I have a new path which is /home/user2/Folder1/Folder2. If I delete user1, my scripts will then fail because they are using the relative path /home/Folder1/Folder2 which its original absolute path is /home/user1/Folder1/Folder2. So I want my new path /home/user2/Folder1/Folder2 to point to /home/Folder1/Folder2 so that my scripts won't fail and I don't want to go through the trouble of opening each script and change the relative path to my new created path. Any idea how I can do this?
I guess, you got confused between soft links and absolute/relative path.
I assume you have a soft link created from "/home/Folder1/Folder2" pointing to "/home/user1/Folder1/Folder2" and you want to delete user1 directory and create user2 directory with same structure. If my assumption is right, recreate the softlink "/home/Folder1/Folder2" to point to "/home/user2/Folder1/Folder2". Your existing scripts will work seamlessly.

ColdFusion Hardlink vs SoftLink traversal searching for Application.cfc (Solaris)

Using the following directory structure on a Solaris 11.3 box running ColdFusion 11. Apache is configured to follow Symbolic links. I have tried using all the following ColdFusion configuration options ( Default order, Until webroot, In webroot). The test2.cfm wont grab the #DATASOURCE# from the Application.cfm and so it is undefined.
/webroot
- Application.cfm
/dir1
/dir2
/dir3
-test1.cfm
/dir4 (softlink to random directory)
-test2.cfm
---------Application.cfm-------------
<CFSET DATASOURCE = "bob" >
<CFAPPLICATION NAME = "bob_app" SESSIONMANAGEMENT = "YES" >
<CFSET SESSION.USERID = "0" >
---------test1/test2.cfm-------------
<cfoutput>
The data source name is #DATASOURCE#
</cfoutput>
Any Suggestions on how to properly add the symbolic link so that search path includes the Application.cfm in the linked directory parent.
I suspect the traversal is getting messed up in the upward recursion because the directory operations are scanning upward from the absolute path of the symlinked directory - which is why symlinks aren't a good pattern for anything traversing up.
I would suggest not using symlinks for any directories which are extensions of the main application - other than static assets.
Alternately, though it's messy and less than ideal, you could just add an Application.cfm to those directories and add <cfinclude template="/Application.cfm"/> ( or include "/Application.cfm"; ) in a <cfscript> block to the beginning of the file.

Win10: ASDF can't load system (ASDF_OUTPUT_TRANSLATION error)

Update 2
I think #faré is right, it's an output translation problem.
So I declared the evironment variable ASDF_OUTPUT_TRANSLATIONS and set it to E:/. Now (asdf:require-system "my-system") yields a different error: Uneven number of components in source to destination mapping: "E:/" which led me to this SO-topic.
Unfortunately, his solution doesn't work for me. So I tried the other answer and set ASDF_OUTPUT_TRANSLATIONS to (:output-translations (t "E:/")). Now I get yet another error:
Invalid source registry (:OUTPUT-TRANSLATIONS (T "E:/")).
One and only one of
:INHERIT-CONFIGURATION or
:IGNORE-INHERITED-CONFIGURATION
is required.
(will be skipped)
Original Posting
I have a simple system definition but can't get ASDF to load it.
(asdf-version 3.1.5, sbcl 1.3.12 (upgraded to 1.3.18 AMD64), slime 2.19, Windows 10)
What I have tried so far
Following the ASDF manual: "4.1 Configuring ASDF to find your systems"
There it says:
For Windows users, and starting with ASDF 3.1.5, start from your
%LOCALAPPDATA%, which is usually ~/AppData/Local/ (but you can ask in
a CMD.EXE terminal echo %LOCALAPPDATA% to make sure) and underneath
create a subpath config/common-lisp/source-registry.conf.d/
That's exactly what I did:
Echoing %LOCALAPPDATA% which evaluates to C:\Users\my-username\AppData\Local
Underneath I created the subfolders config\common-lisp\source-registry.conf.d\ (In total: C:\Users\my-username\AppData\Local\config\common-lisp\source-registry.conf.d\
The manual continues:
there create a file with any name of your choice but with the type conf, for instance 50-luser-lisp.conf; in this file, add the following line to tell ASDF to recursively scan all the subdirectories under /home/luser/lisp/ for .asd files: (:tree "/home/luser/lisp/")
That’s enough. You may replace /home/luser/lisp/ by wherever you want to install your source code.
In the source-registry.conf.d folder I created the file my.conf and put in it (:tree "C:/Users/my-username/my-systems/"). This folder contains a my-system.asd.
And here comes the weird part:
If I now type (asdf:require-system "my-system") in the REPL I get the following error:
Can't create directory C:\Users\my-username\AppData\Local\common-lisp\sbcl-1.3.12-win-x86\C\Users\my-username\my-systems\C:\
So the problem is not that ASDF doesn't find the file, it does -- but (whatever the reason) it tries to create a really weird subfolder hierarchy which ultimately fails because at the end it tries to create the folder C: but Windows doesn't allow foldernames containing a colon.
Another approach: (push path asdf:*central-registry*)
If I try
> (push #P"C:/Users/my-username/my-systems/" asdf:*central-registry*)
(#P"C:/Users/my-username/my-systems/"
#P"C:/Users/my-username/AppData/Roaming/quicklisp/quicklisp/")
> (asdf:require-system "my-system")
I get the exact same error.
I don't know what to do.
Update
Because of the nature of the weird path ASDF was trying to create I thought maybe I could bypass the problem by specifying a relative path instead of an absolute one.
So I tried
  (:tree "\\Users\\my-username\\my-systems")
in my conf file. Still the same error.
Ahem. It looks like an output-translations problem.
I don't have a Windows machine right now, but this all used to work last time I tried.
Can you setup some ad hoc output-translations for now that will make it work?

Copying folder except for one subfolder in Yeoman

I am working on this Yeoman project, and I am copying some files from a template to my new app directory.
This line is doing the job well:
this.fs.copyTpl(this.templatePath(''),
this.destinationPath(this.project_name_slugified+'/'));
Everything comes from the template folder and goes to the root folder of the project.
But when someone adds a flag '--nr' I want to exclude one subfolder that has been copied. So yo my-gen my_app_name --rf should copy EVERYTHING unless this subfolder.
I tried the !-glob notation, but it's not working. I did something like as first parameter:
[this.templatePath('**'),this.templatePath('!subfolder/subfolder_to_be_excluded')]
So second parameter was set to exclude the subfolder that is not necessary
I also tried deleting (delete method), but it seems that the file is not available immediately.
It's not working anyway. Any ideas? Promisifying the copyTpl would work?
By calling this.templatePath('!subfolder/subfolder_to_be_excluded'), you end up generating a broken path: /absolute/path/!subfolder/etc.
Use it without this.templatePath given you don't need the absolute path to apply the filtering.
this.fs.copyTpl(
[
this.templatePath('**'),
'!subfolder/subfolder_to_be_excluded'
],
this.destinationPath(this.project_name_slugified + '/'),
templateContext
);

Resources