-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fahad Hossain
committed
Dec 7, 2018
0 parents
commit bc58fb9
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# i3-sensible-app | ||
|
||
Opens a predefined app based on the currently focused i3 workspace. | ||
|
||
## Usage | ||
Change your hotkey from i3-sensible-terminal to i3-sensible-app | ||
|
||
```diff | ||
-bindsym Mod4+Return exec i3-sensible-terminal | ||
+bindsym Mod4+Return exec i3-sensible-app | ||
``` | ||
|
||
Create the default apps config in `~/.config/i3/defaults.json` | ||
|
||
Example: | ||
|
||
```json | ||
{ | ||
"1: ": ["albert", "toggle"], | ||
"2: ": ["google-chrome-stable"], | ||
"3: ": ["i3-sensible-terminal"], | ||
"4: ": ["code"], | ||
"5: ": ["nautilus"], | ||
"6: ?": ["albert", "toggle"], | ||
"7: ": ["evince"], | ||
"8: ?": ["albert", "toggle"], | ||
"9: ": ["xdg-open", "http://localhost:6680/iris"], | ||
"10: ": ["mpv", "--idle"] | ||
} | ||
``` | ||
|
||
**Now just shift to your desired workspace and press <kbd>⊞ Win</kbd> + <kbd>Enter ⏎</kbd>** | ||
|
||
|
||
## Installation | ||
|
||
### Pre-requisites | ||
|
||
* i3 (and i3-msg) | ||
* go (for compilation) | ||
|
||
### INSTALL (with go) (*preferred*) | ||
Open a terminal and run | ||
|
||
```bash | ||
go get github.com/fa7ad/i3-sensible-app | ||
``` | ||
|
||
### INSTALL (from git) | ||
Clone this repo and change into the directory | ||
|
||
```bash | ||
git clone https://github.com/fa7ad/i3-sensible-app.git | ||
cd i3-sensible-app/ | ||
``` | ||
|
||
Build the binary | ||
|
||
```bash | ||
go build | ||
``` | ||
|
||
Move the directory to a folder in PATH | ||
|
||
```bash | ||
sudo install -Dm755 i3-sensible-app /usr/bin | ||
``` | ||
|
||
### INSTALL (manual) | ||
Download the binary from [releases](https://github.com/fa7ad/i3-sensible-app/releases) | ||
|
||
## LICENSE | ||
MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
var conf []byte | ||
|
||
type workspace struct { | ||
Name string | ||
Focused bool | ||
} | ||
|
||
func getEnv(env, def string) string { | ||
val, ok := os.LookupEnv(env) | ||
if ok { | ||
return val | ||
} | ||
return def | ||
} | ||
|
||
func init() { | ||
fback := path.Join(getEnv("HOME", "~"), ".config") | ||
file := path.Join(getEnv("XDG_CONFIG_HOME", fback), "i3", "defaults.json") | ||
cfile, err := filepath.Abs(file) | ||
if err != nil { | ||
log.Fatalf("Config file %s doesn't exist", file) | ||
} | ||
conf, err = ioutil.ReadFile(cfile) | ||
if err != nil { | ||
log.Fatalf("Failed to read config file %s!", cfile) | ||
} | ||
} | ||
|
||
func getFocusedWs(wss []workspace) (workspace string, err error) { | ||
for _, ws := range wss { | ||
if ws.Focused { | ||
workspace = ws.Name | ||
} | ||
} | ||
if len(workspace) < 1 { | ||
err = errors.New("no active workspace found") | ||
} | ||
return | ||
} | ||
|
||
func main() { | ||
var config map[string]([]string) | ||
err := json.Unmarshal(conf, &config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
out, err := exec.Command("i3-msg", "-t", "get_workspaces").Output() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var output []workspace | ||
json.Unmarshal(out, &output) | ||
ws, err := getFocusedWs(output) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
args := config[ws] | ||
cmd := exec.Command(args[0], args[1:]...) | ||
err = cmd.Start() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |