Skip to content

Commit 790ee1e

Browse files
authored
Merge pull request ywangd#395 from sn3ksoftware/dev
Adds ‘-O’ option to curl
2 parents 3549369 + 7d363c3 commit 790ee1e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bin/curl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import argparse
77
import requests
88

9+
try:
10+
from urllib.parse import urlparse
11+
except ImportError:
12+
from urlparse import urlparse
13+
914
try:
1015
import clipboard
1116
except ImportError:
@@ -16,6 +21,12 @@ def main(args):
1621
ap = argparse.ArgumentParser()
1722
ap.add_argument('url', nargs='?', help='the url to read (default to clipboard')
1823
ap.add_argument('-o', '--output-file', help='write output to file instead of stdout')
24+
ap.add_argument(
25+
'-O',
26+
'--remote-name',
27+
action='store_true',
28+
help='write output to a local file named like the remote file we get'
29+
)
1930
ap.add_argument(
2031
'-X',
2132
'--request-method',
@@ -50,6 +61,12 @@ def main(args):
5061
if ns.output_file:
5162
with open(ns.output_file, 'w') as outs:
5263
outs.write(r.text)
64+
elif ns.remote_name:
65+
# get basename of url
66+
url_path = urlparse(url).path
67+
filename = url_path.split('/')[-1]
68+
with open(filename, 'w') as outs:
69+
outs.write(r.text)
5370
else:
5471
print(r.text)
5572

0 commit comments

Comments
 (0)