Python script to print clickable link on the terminal
You can CTRL-click the link or press ENTER
to open the file browser.
import curses
import os
import subprocess
def main(stdscr):
# Setup curses
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)
curses.curs_set(0)
stdscr.clear()
# Get current directory
current_dir = os.path.abspath(os.getcwd())
url = f"file://{current_dir}"
# Display instructions and link
stdscr.addstr(0, 0, "Press ENTER to open file browser, 'q' to quit")
stdscr.addstr(2, 0, url, curses.color_pair(1) | curses.A_UNDERLINE)
stdscr.refresh()
# Handle input
while True:
key = stdscr.getch()
if key == ord('q'):
break
elif key == ord('\n'):
# Launch default file browser (xdg-open for Linux)
subprocess.run(['xdg-open', current_dir])
break
if __name__ == '__main__':
curses.wrapper(main)
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow