Skip to content

Commit

Permalink
Fix code issue in running shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
wenijinew committed Nov 15, 2023
1 parent f6b7057 commit f9ef22e
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ eutmux.py.log
tmux_commands.txt
__pycache__
/.requirements.installed.txt
/dynamic.glamour.yaml
Empty file modified cpu.sh
100644 → 100755
Empty file.
Empty file modified disk.sh
100644 → 100755
Empty file.
97 changes: 97 additions & 0 deletions dynamic.glamour.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
theme: burgundy-red
general:
options:
status: true
status-fg: "#a9b0b0"
status-bg: "#011814"
status-justify: left
status-left-length: 100
status-right-length: 100
window-status-separator: ' '
terminal-overrides: ",xterm*:Tc"
default-terminal: "screen-256color"
escape-time: 10
status-interval: 3
focus-events: true
display-time: 10000
renumber-windows: true
clock-mode-colour: "#5ab756"
_fg_highlight: "#5e35a9"
_bg_highlight: "#d3c598"
_style: "nobold,nounderscore,noitalics"
styles:
message-style:
fg: "#9ad398"
bg: ""
style: ""
message-command-style:
fg: "#d398b3"
bg: ""
style: ""
pane-border-style:
fg: "#2b3e3b"
bg: ""
style: ""
pane-active-border-style:
fg: "#7ac577"
bg: ""
style: ""
popup-style:
fg: "#9ad398"
bg: "#011814"
popup-border-style:
fg: "#9ad398"
bg: ""
commands:
- bind-key 'g' run-shell 'glamour.tmux -d'
- bind-key 'G' run-shell 'glamour.tmux -D'
- bind-key 'a' display-popup 'glamour.tmux -a'
- bind-key 'r' run-shell 'glamour.tmux -r'
- bind-key 'C-j' setw synchronize-panes on
- bind-key 'C-k' setw synchronize-panes off
- bind-key -n 'M-l' select-window -l
- bind-key -n 'M-j' select-pane -R
- bind-key -n 'M-k' select-pane -D
- bind-key -n 'M-Left' select-window -p
- bind-key -n 'M-Right' select-window -n
status_left:
session:
enabled: "on"
tmux_option: " #S "
window:
active:
window_name: " #W "
window_index: " #I"
icon: ""
inactive:
window_name: " #W "
window_index: " #I"
icon: ""
status_right:
directory:
enabled: true
tmux_option: " #{b:pane_current_path} "
icon: ""
decorator: ""
fg_option: "#011814"
bg_option: "#d3c598"
fg_icon: "#011814"
bg_icon: "#b79f56"
fg_decorator: "#b79f56"
date:
enabled: true
icon: ""
tmux_option: " v%V %a %Y-%m-%d %H:%M:%S "
cpu:
enabled: true
icon: ""
tmux_option: " #(source cpu.sh) "
memory:
enabled: true
icon: ""
tmux_option: "#(source memory.sh)"
disk:
enabled: true
icon: ""
tmux_option: " #(source disk.sh) "
14 changes: 11 additions & 3 deletions eutmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import os

import yaml
from utils import get_tmux_option, run_shell_command
from yaml import Loader

from utils import get_tmux_option, run_shell_command

UTF_8 = "utf-8"
EMPTY = ""

Expand Down Expand Up @@ -496,7 +497,7 @@ def init(config_file="eutmux.yaml"):
eutmux_dynamic_config_file_name = get_tmux_option(
"@eutmux_dynamic_config_file_name", config_file
)
eutmux_workdir = os.getenv("EUTMUX_WORKDIR")
eutmux_workdir = os.getenv("EUTMUX_WORKDIR", os.curdir)
os.chdir(eutmux_workdir)
with open(eutmux_dynamic_config_file_name, "r", encoding=UTF_8) as config:
eutmux = yaml.safe_load(config)
Expand All @@ -519,7 +520,14 @@ def init(config_file="eutmux.yaml"):
theme_filename = f"{eutmux_config_home}/{theme_filename}"
else:
theme_filename = "eutmux.theme.yaml"

<<<<<<< HEAD
<<<<<<< HEAD

=======
>>>>>>> 9e9ce1d (Fix code issue in running shell command)
=======
print(theme_filename)
>>>>>>> fa2ca52 (temp)
with open(theme_filename, "r", encoding=UTF_8) as theme_file:
theme_config = yaml.safe_load(theme_file)
theme = Theme(theme_config)
Expand Down
Empty file modified eutmux.tmux
100644 → 100755
Empty file.
Empty file modified memory.sh
100644 → 100755
Empty file.
23 changes: 22 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Provide utilities functions."""
import shlex
import subprocess
from subprocess import TimeoutExpired

UTF_8 = "utf-8"
EMPTY = ""
Expand All @@ -21,10 +22,30 @@ def get_tmux_option(name, default_value):
def run_shell_command(command, default_output=None):
"""Run shell command."""
command_args = shlex.split(command)
<<<<<<< HEAD
result = (
subprocess.popen(command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.Popen(command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
)
print(result.returncode)
if result.returncode != 0:
return default_output
else:
return result.stdout.strip()
=======
with (
subprocess.Popen(command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
) as process:
try:
outs, errs = process.communicate(timeout=3)
except TimeoutExpired:
process.kill()
outs, errs = process.communicate()
raise TimeoutExpired
output = outs.decode().strip()
return output if output and len(output) > 0 else default_output


if __name__ == "__main__":
value = get_tmux_option("@eutmux_base_color_total", 5)
print(value)
>>>>>>> 9e9ce1d (Fix code issue in running shell command)
Empty file modified utils.sh
100644 → 100755
Empty file.

0 comments on commit f9ef22e

Please sign in to comment.