Operating on a file with overly long name - string

When I set up the ProtonMail Bridge CLI, it generated a hierarchy in my .password-store where the top level is called protonmail-credentials. This contains a subfolder where the name is a gibberish string enclosed in single quotes with--according to wc -c--153 characters. The name of the item under this is itself a 93-character string.
I would like to be able to operate on this item with pass, but wildcards apparently don't work for paths in pass, and dealing with such absurdly long strings which differ from setup to setup by typing everything out is not at all viable.
I am able to isolate the subfolder name with ls -1 .password-store/protonmail-credentials, which gives me the string beginning 'cHJv and continuing onward. I thought I could assign this to an environment variable with export $LONGDIRNAME=$(ls -1 .password-store/protonmail-credentials), but bash throws a 'not a valid identifier' error and thinks I'm trying to set the variable to a string beginning `=cHJv. I do not know why it is adding a backtick and equals sign to the string before attempting to set the variable.
Renaming either of these breaks ProtonMail Bridge's functionality, so mv is not an option either. What should I do with these strings to make the usable in pass?

Related

How to extract substring (path to folder) from string using batch script or PowerShell

I have been trying to remove in batch script "=" character from string by using this:
set Path_var=%Path_var:^==%
Unfortunately this does not work... I tried also some other common solutions like:
set Path_var=%Path_var:"="=%
set Path_var=%Path_var:'='=%
But without success. Maybe it would be worthy also to explain for what I need it as I am aware you may be able to provide better solution. I extract one line from xml configuration file. The line is following:
<burning addDicomViewer="true" finalizeMedium="true" dicomViewer="C:\user\App_folder\App-name_subfolder_1.1.1_Setup" burnVerification="true" numberOfCopies="0" cleanupProjectData="false" volumeName="Patient Medium"/>
I need to extract from this line this path: "C:\user\App_folder\App-name_subfolder_1.1.1_Setup" (The path will not always be the same)
My strategy was to simply remove definite number of characters before the path as I know this setting will always be the same and therefore the length of the string won`t change.
set /p Path_var= < temp_file01.txt
set Path_var=%Path_var:~81,100%
Then I wanted to use simply substitution to remove the rest. For example:
set Path_var=%Path_var:burnVerification=%
But I ran into problem that my string contains characters like "=" which I can not remove by this method. (Because obviously there are handled as operators) What I was also wondering is what I should do if there will be a space character in my path. Then when I attempt to remove the empty characters at the end I also invalidate my path.
I know batch scripts are not the best for manipulation with strings, but I do not have other choice as my boss want me to use scripting language which does not need compiling.
I asked my work colleague for help and he came with following PowerShell solution:
$path_temp_file01 = "C:\user\temp\tmpFile_backup_script01.txt"
$path_temp_file02 = "C:\user\temp\tmpFile_backup_script02.txt"
$string = [IO.File]::ReadAllText($path_temp_file01)
$Start = $string.IndexOf("C:")
$string = $string.substring($Start)
$End =$string.IndexOf("""")
$string = $string.substring(0,$End)
$string > $path_temp_file02
It works for me. I post it here in the case someone needs similar solution or has better idea how to do that.

String value with dots changed while assignig to "..(class).." - Google Apps Script

I have a problem with assigning a string value containg dots to a variable.
For example, after using this assignment:
var txt = "company.com.en";
the variable txt is set to "company.(class)"
How to avoid this behaviour, I want to keep this value unchanged.
OK, I've found my problem. It is really silly, but it is a feature of Debug viewer in Google Apps Script. String variables with dots are shown in this way (with ".(class)" string included). The oryginal value of variable remains unchanged. So, case closed.

How to match line & error in Sublime Text 3?

How can I match this error in the build with regex to locate line and file with result_line_regex & result_file_regex?
project4.dpr(9) Hint: H2164 Variable 'I' is declared but never used in 'Project3'
I have tried this but it won't work.
"result_file_regex": "^.*\\(.*)/.?(.*)$",
"result_line_regex": "^([^\\]*)\.(\w+)$",
As already mentioned in the comments, file_regex is the setting that gets passed to result_line_regex (have a look at the run() method signature of class ExecCommand in Packages/Default/exec.py).
A good regex in your case would be ^([\w-]+\.\w+)\((\d+)\). The first group captures something like my-file.ext and the second one the digit(s) in parentheses.
In order to set that expression in a string in the json file you need to escape each backslash with another backslash (\ is the escape character in strings), so it becomes:
"file_regex": "^([\\w-]+\\.\\w+)\\((\\d+)\\)"
Notice that the matched file has to be in the path of the file that is active when triggering the build system. If you want it to be relative to a certain path no matter where you trigger the build, you can also pass a working directory like:
"working_dir": "/path/to/my/source"
This will be set as result_base_dir in the output view.

Simple string replacement set of rules

I have an application where users set up a bunch of objects by filling up a bunch of text boxes which represent values that these objects will take. Just like setting up a Person object which requires you to enter a Name and a LastName properties.
Now I want to introduce global variables that the user will be able to assign values to, or which's values will change during the execution of the program. And I want the user to be able to use them when filling up any object's properties. My first idea was to choose an special character that will mark the beginning of a variable name, and then let the user use the character itself twice to represent the character itself.
For instance, say I have a global variable called McThing. Then, say the symbol I choose to mark the beginning of a variable is %. The user would then be able to enter as a person's last name the string "Mc. %McThing", which then I'd replace using the value of McThing. If McThing's value is "Donalds", the last name would become "Mc. Donalds".
The problem with this is that, if I'd have a variable called He and another called Hello and the user enters "%Hello" as the string I wouldn't know which variable needs to be replaced. I could change my rules to, for instance, use the "%" symbol to mark both the beginning and the end of the variable name. But I'm not sure whether this will cause any other problem.
What would be the simplest possible set of rules to achieve this such that the user will be able to represent every possible string without ambiguities? Ideally, the variable names can have any character but I could restrict their names to a given set of characters.
Your approach of marking both beginning and end with % has one problem. What happens if the input string is %foo%%bar%? Do I get the value of foo and the value of bar? Or do I get the value of foo%bar? (Of course if % in variable names isn't allowed, this isn't a problem.)
The simplest way I can think of to avoid this problem is to use one symbol for the beginning and another (e.g. #) for the end. That should avoid any ambiguity. If the user wants a # in text or a variable name, he escapes it like so: %#. This causes no problems, since empty variable names are not a thing (at least I hope not).
It will be fine and easy to implement on the assumptions that:
You have no empty variable names (i.e. if we see a %% is that a % or an empty variable name?)
Variable names cannot contain %s (i.e. if we see a % in a variable name, is that the end or a %?)
OR
Variable names cannot start or end with % and you cannot have 2 variable names in a row
(i.e. is %a%%b% = a and b or a%b?)
These assumptions will ensure that any %% always represents a % character, and any % always represents the start or the end of the string.
These assumptions might not necessarily be required, but at the very least they will make the implementation a lot more difficult (with the above assumptions, we never have to look more than 1 character forward).
An alternative with no such restrictions, loosely based on the way C/Java/etc. does it:
Have % take on a role similar to \ in C/Java/etc. - use:
%s to denote the start of the string
%e to denote the end of the string
%% to denote the % character
You can also use the same characters to represent the start and end, but, we may as well make them different so it's easier to read.

bash reading string with spaces as parameter

I found on a forum how to solve when a function is called with more parameters and each as string with spaces, but how to read string with spaces from input, I mean when somebody calls my script.
In this case, user should send two txt files addresses. So, I know the suffix, but he could also send files that haven't got that suffix. So, is there any way how to read the two file addresses?
The script arguments are kept in so called "positional parameters". For example, if the script is called as
script.sh /path/to/1.txt 2.csv
$1 will contain the first file path and $2 the second one.

Resources