Coder Social home page Coder Social logo

xcwd's Introduction

xcwd - X current working directory

xcwd is a simple tool that prints the current working directory of the currently focused window.

The main goal is to launch applications directly into the same directory as the focused applications. This is especially useful to open a new terminal or a file explorer.

Disclaimer

This program is basically a hack, but it works well with my setup and I hope it will work for you as well :)

This script can't retrieve the working directory of a "single instance application" nor terminal multiplexer, e.g.:

  • tmux, screen
  • lilyterm
  • konsole
  • urxvtc with urxvtd
  • applications with tabs

The application works with the following terminals:

  • urxvt
  • xterm
  • gnome terminal
  • terminology

How it works

  • Get the handle of the focused window;
  • Try to get the PID of the program using the window's attributes:
    • If _NET_WM_PID is set, xcwd just reads the value;
    • Otherwise it reads the _NET_WM_CLASS and compares it to the name of all the running processes;
  • Find the deepest child process;
  • Print the working directory of this process to stdout.

If one of these steps fail, xcwd prints the content of the $HOME variable.

Requirements

  • Linux or FreeBSD
  • libX11-dev

Installation

Running xwcd

Simply invoke the 'xcwd' command.

Examples:

  • urxvt -cd "`xcwd`"
  • xterm -e "cd `xcwd` && /bin/zsh"
  • gnome-terminal --working-directory="`xcwd`"
  • pcmanfm "`xcwd`"

i3 Configuration

  • bindsym $mod+Shift+Return exec urxvt -cd "`xcwd`"
  • bindsym $mod+Shift+Return exec xterm -e "cd `xcwd` && $SHELL"
  • bindsym $mod+Shift+Return exec gnome-terminal --working-directory="`xcwd`"
  • bindsym $mod+p exec pcmanfm "`xcwd`"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.