'url n' prints URL of item n

This commit is contained in:
Callum Brown 2020-12-20 11:51:59 +00:00
parent a8a0be4754
commit d3734a9a26
1 changed files with 19 additions and 2 deletions

21
av98.py
View File

@ -1482,8 +1482,25 @@ Use 'ls -l' to see URLs."""
@needs_gi
def do_url(self, *args):
"""Print URL of most recently visited item."""
print(self.gi.url)
"""Print the URL of an item.
'url' prints the URL of the most recently visited item.
'url n' prints the URL of item n."""
# If no argument print current URL
if args[0] == '':
print(self.gi.url)
return
# If there is a valid integer argument print url of that item.
try:
n = int(args[0])
except ValueError:
print("Invalid item number.")
return
try:
gi = self.lookup[n-1]
except IndexError:
print ("Index too high!")
return
print(gi.url)
### Bookmarking stuff
@restricted