This repository was archived by the owner on Nov 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
[DO NOT MERGE} initial zsh support #355
Open
detiber
wants to merge
8
commits into
p-e-w:master
Choose a base branch
from
detiber:zsh2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5681dd
initial zsh support
detiber 2eea484
zsh fixes for ps and wget Termlets
detiber 98f1eef
use SHELL env variable to determine shell to launch, fallback to defa…
detiber 5a9ea24
cleanup variable naming for trim command
detiber d4a68e7
separate zsh termlets from bash termlets, do not hardcode shell paths
detiber 44eb025
improve zsh handling of control sequences
detiber 76ce1a0
Fix crash when attempting to display popup menu
detiber f9153f3
some additional debugging and attempts to cleanup crash issue with zsh
detiber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,8 @@ | ||
Requirements | ||
- gsettings set org.gnome.finalterm shell-path /usr/bin/zsh | ||
- add the following to ~/.zshrc: | ||
``` | ||
if [ -n "$FINALTERMSCRIPT" ]; then | ||
. $FINALTERMSCRIPT | ||
fi | ||
``` |
This file contains hidden or 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,11 @@ | ||
# NOTE: xterm properly ignores sequences of this type as unknown, | ||
# while some other terminals (such as GNOME Terminal) print them | ||
control_sequence="\e]133;" | ||
for argument in "$@"; do | ||
control_sequence="$control_sequence$argument;" | ||
done | ||
# TODO: Remove last semicolon | ||
control_sequence="$control_sequence\a" | ||
|
||
# TODO: Should "-ne" be added here? | ||
echo "$control_sequence" |
This file contains hidden or 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 @@ | ||
echo -ne "$1" |
This file contains hidden or 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 @@ | ||
send_control_sequence "$(final_term_control_sequence 'G' "$1" "$2")" |
This file contains hidden or 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 @@ | ||
echo "$(final_term_control_sequence 'F' "$1")" |
This file contains hidden or 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,3 @@ | ||
# NOTE: Nested double quotes look strange, but are both valid and necessary; | ||
# see http://stackoverflow.com/questions/4031007 | ||
echo "$(final_term_control_sequence 'E' "$1")" |
This file contains hidden or 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,83 @@ | ||
#!/usr/bin/zsh | ||
|
||
# Final Term's customizations start here | ||
finalterm_fpath="@PKGDATADIR@/Startup/zsh_functions" | ||
if [ -d $finalterm_fpath ]; then | ||
fpath=($finalterm_fpath $fpath) | ||
fi | ||
FPATH="${finalterm_fpath}:${FPATH}" | ||
export FPATH | ||
|
||
autoload send_control_sequence | ||
autoload final_term_control_sequence | ||
|
||
# Logic for prompt and command detection | ||
function send_return_code() { | ||
# Send sequence containing the return code of the last command | ||
send_control_sequence "$(final_term_control_sequence 'D' "$?")" | ||
} | ||
|
||
precmd() { | ||
# Send sequence marking a command prompt | ||
send_control_sequence "$(final_term_control_sequence 'A')" | ||
} | ||
|
||
preexec() { | ||
# Send sequence containing the command to be executed | ||
send_control_sequence "$(final_term_control_sequence 'C' "$1")" | ||
} | ||
|
||
PROMPT_COMMAND=send_return_code;$PROMPT_COMMAND | ||
|
||
# Send sequence marking the start of a command | ||
PS1=$PS1$(final_term_control_sequence 'B') | ||
|
||
|
||
# Logic for terminal commands | ||
function trim() { | ||
local var=$1 | ||
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters | ||
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters | ||
echo -n "$var" | ||
} | ||
|
||
function send_commands() { | ||
send_control_sequence "$(final_term_control_sequence 'H' "$1" '#' "${@:2}")" | ||
} | ||
|
||
pushd "@PKGDATADIR@/TerminalCommands" > /dev/null | ||
while IFS= read -r line; do | ||
stripped_line=$(trim "$line") | ||
|
||
if [ -n "$stripped_line" ]; then | ||
# Non-empty line | ||
if [ "${stripped_line:0:1}" != "#" ]; then | ||
# Non-comment line | ||
# Split on "=" character and escape double quotes used for command arguments | ||
name=$(trim "${stripped_line%%\=*}") | ||
cmds=$(trim "${${stripped_line#*\=}//\"/\\\"}") | ||
|
||
alias ",$name"="send_commands \"$cmds\"" | ||
fi | ||
fi | ||
done <*.ftcommands | ||
popd > /dev/null | ||
|
||
|
||
# Termlet-related logic | ||
function run_termlet() { | ||
if [ -t 1 ]; then | ||
/usr/bin/zsh "@PKGDATADIR@/Termlets/$@" | ||
else | ||
/usr/bin/zsh "$@" | ||
fi | ||
} | ||
|
||
# Set up termlet aliases | ||
pushd "@PKGDATADIR@/Termlets" > /dev/null | ||
for filename in *; do | ||
alias $filename="run_termlet '$filename'" | ||
done | ||
popd > /dev/null | ||
|
||
cd ~ |
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,26 +1,44 @@ | ||
#!/bin/bash | ||
|
||
if [ -n "$ZSH_VERSION" ]; then | ||
autoload text_menu_start | ||
autoload text_menu_end | ||
autoload final_term_control_sequence | ||
autoload send_control_sequence | ||
fi | ||
|
||
# IFS is '\n' | ||
IFS=$'\012' | ||
psoutput=($(ps "$@")) | ||
|
||
headeridx=0 | ||
while [ -z ${psoutput[$headeridx]+x} ]; do | ||
((headeridx+=1)) | ||
done | ||
|
||
# Just in case PPID could be displayed before PID, search for ' PID' | ||
pid_index=$(awk -v a="${psoutput[0]}" -v b=' PID' 'BEGIN{print index(a,b)}') | ||
pid_index=$(awk -v a="${psoutput[$headeridx]}" -v b=' PID' 'BEGIN{print index(a,b)}') | ||
# don’t use $() in loops, as it spawns a sub-process, so get markings out of the loop. | ||
begin_mark=$(text_menu_start '3') | ||
end_mark=$(text_menu_end '3') | ||
# last character position of PID display. | ||
let pid_end=pid_index+4 | ||
# display 1st line as is, then destroy it. | ||
echo -e ${psoutput[0]} | ||
unset psoutput[0] | ||
|
||
# display header line as is and destroy it | ||
echo -e ${psoutput[$headeridx]} | ||
if [ -n "$ZSH_VERSION" ]; then | ||
psoutput[$headeridx]=() | ||
else | ||
unset psoutput[$headeridx] | ||
fi | ||
|
||
for line in ${psoutput[@]}; do | ||
# Content line | ||
left_part=${line:0:${pid_end}-1} | ||
pid_part=${left_part##* } | ||
# Remove pid_part from left_part | ||
left_part=${left_part:0:${#left_part}-${#pid_part}} | ||
right_part=${line:pid_end-1} | ||
right_part=${line:${pid_end}-1} | ||
modified_line="$left_part$begin_mark$pid_part$end_mark$right_part" | ||
echo -e "$modified_line" | ||
done |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -242,16 +242,37 @@ public class Terminal : Object { | |
private void run_shell() { | ||
Environment.set_variable("TERM", Settings.get_default().emulated_terminal, true); | ||
|
||
string[] arguments = { Settings.get_default().shell_path, "--rcfile", | ||
Config.PKGDATADIR + "/Startup/bash_startup", "-i" }; | ||
string shell = Environment.get_variable("SHELL") ?? Settings.get_default().shell_path; | ||
string shell_basename = Filename.display_basename(shell); | ||
|
||
string[] valid_shells = { "zsh", "bash" }; | ||
|
||
if (!(shell_basename in valid_shells)){ | ||
message(_("shell defined in environment is not supported, falling back to bash")); | ||
shell = Settings.get_default().shell_path; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, I'll add logic to force bash if Settings.get_default().shell_path is not a valid shell. Thinking about it, I should also test to make sure that the shell referenced by $SHELL or shell_path actually exists as well. |
||
shell_basename = Filename.display_basename(shell); | ||
} | ||
|
||
string shell_include = Config.PKGDATADIR + "/Startup/" + shell_basename + "_startup"; | ||
|
||
string[] arguments = {}; | ||
switch(shell_basename){ | ||
case "bash": | ||
arguments = { shell, "--rcfile", shell_include, "-i" }; | ||
break; | ||
case "zsh": | ||
Environment.set_variable("FINALTERMSCRIPT", shell_include, true); | ||
arguments = { shell, "-i" }; | ||
break; | ||
} | ||
|
||
// Add custom shell arguments | ||
foreach (var argument in Settings.get_default().shell_arguments) { | ||
arguments += argument; | ||
} | ||
|
||
// Replace child process with shell process | ||
Posix.execvp(Settings.get_default().shell_path, arguments); | ||
Posix.execvp(shell, arguments); | ||
|
||
// If this line is reached, execvp() must have failed | ||
critical(_("execvp failed")); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
autoload
is not enabled by default in bash.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that is why the test for $ZSH_VERSION, though thinking about it a bit, it might make sense to create zsh wrappers that do the autoloading and then source the bash scripts instead.