21
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 get the human-form of the name of the final path segment in a url:
|
|
5
|
|
6 xclip -o | sed 's/_//' | sed 's/.html//'
|
|
7 """
|
|
8
|
|
9 import sys
|
|
10
|
|
11 def url2txt(url):
|
|
12 """gets the text equivalent of a URL"""
|
|
13 url = url.rstrip('/')
|
|
14 if '/' in url:
|
|
15 url = url.rsplit('/')[-1]
|
|
16 if '.' in url:
|
|
17 url = url.split('.', 1)[0]
|
|
18 url = url.replace('_', ' ')
|
|
19 return url
|
|
20
|
|
21
|
|
22 def main(args=sys.argv[1:]):
|
|
23 """CLI"""
|
|
24 for arg in args:
|
|
25 print url2txt(arg)
|
|
26
|
|
27
|
|
28 if __name__ == '__main__':
|
|
29 main()
|