Skip to content

Commit 50d0f7d

Browse files
committed
More improvements
Signed-off-by: Piyush Ajmani <[email protected]>
1 parent c5fec0e commit 50d0f7d

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ Now you can use it globally
1313
## Usage
1414

1515
### Simple shortening
16+
<code> shortlr -l 'url' </code>
1617

1718
If the argument is a URL, the output a shortened URL.
1819

1920
#### Example
2021

21-
<code> shortlr http://google.com </code>
22+
<code> shortlr -l http://google.com </code>
2223

2324
will produces a short link pointing to google.
2425

shortlr

+22-35
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,28 @@ const querystring = require('querystring');
1010
const http = require('http');
1111

1212

13-
if (process.argv[2] && ValidURL(process.argv[2])) {
14-
const customShortcode = process.argv[3];
15-
PostCode(process.argv[2],secret,customShortcode);
16-
}
13+
if (process.argv[2] === '-l') {
14+
const customShortcode = process.argv[4];
15+
PostCode(process.argv[3], secret, customShortcode);
16+
} else if (process.argv[2] === '-s') {
17+
let remote = null;
18+
if (process.argv[3]) {
19+
remote = process.argv[3];
20+
} else {
21+
remote = 'origin';
22+
}
23+
24+
exec('git config --get remote.' + remote + '.url', function (error, stdout, stderr) {
25+
if (error) {
26+
console.error(`exec error: ${error}`);
27+
return;
28+
}
29+
30+
let str = `${stdout}`;
31+
PostCode(str);
32+
});
1733

18-
else if (process.argv[2] !== '-s') {
34+
} else {
1935
const customShortcode = process.argv[5];
2036
const directory = process.argv[4];
2137
let remote = null;
@@ -48,33 +64,14 @@ else if (process.argv[2] !== '-s') {
4864

4965
console.log("Pushing code to " + remote + " " + branch);
5066
exec('git push ' + remote + ' ' + branch, function (error, stdout, stderr) {
51-
if(error){
67+
if (error) {
5268
console.error(`exec error: ${error}`);
5369
return;
5470
}
5571
})
5672
});
5773

58-
} else {
59-
let remote = null;
60-
if (process.argv[3]) {
61-
remote = process.argv[3];
62-
} else {
63-
remote = 'origin';
64-
}
65-
66-
exec('git config --get remote.' + remote + '.url', function (error, stdout, stderr) {
67-
if (error) {
68-
console.error(`exec error: ${error}`);
69-
return;
70-
}
71-
72-
let str = `${stdout}`;
73-
PostCode(str);
74-
});
75-
7674
}
77-
7875
function PostCode(url, secret, code) {
7976

8077
url = url.replace(/(\r\n|\n|\r)/gm, "");
@@ -103,14 +100,4 @@ function PostCode(url, secret, code) {
103100

104101
post_req.write(post_data);
105102
post_req.end();
106-
}
107-
108-
function ValidURL(str) {
109-
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
110-
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name
111-
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
112-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
113-
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
114-
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
115-
return pattern.test(str);
116103
}

0 commit comments

Comments
 (0)