-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from psseelman/feature/hex-ascii-fish-path
Add Fish PATH Hex Converter
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
{ | ||
"api": 1, | ||
"name": "Fish PATH Hex Converter", | ||
"description": "Takes a regular PATH and converts it to use hex ascii characters ex. -L/usr/local/opt/[email protected]/lib -> \x2dL/usr/local/opt/openssl\x401\x2e1/lib"", | ||
"author": "Paul Seelman", | ||
"icon": "broom", | ||
"tags": "fish_user_paths, fish, hex, ascii, path, var" | ||
} | ||
**/ | ||
function convert(string) { | ||
var chars = string.split(""); | ||
var dict = { | ||
" ": ":", | ||
"%": "25", | ||
"&": "26", | ||
"+": "2b", | ||
"-": "2d", | ||
".": "2e", | ||
"*": "2a", | ||
":": "3a", | ||
"@": "40", | ||
";": "3b" | ||
}; | ||
|
||
for (var i = chars.length - 1; i >= 0; i--) { | ||
var char = chars[i]; | ||
var hex = dict[char]; | ||
|
||
if (hex !== undefined) { | ||
var slash_x = '\\x'; | ||
chars[i] = slash_x.concat(hex); | ||
} | ||
} | ||
|
||
return chars.join(""); | ||
} | ||
|
||
function main(input) { | ||
input.text = convert(input.text); | ||
} |