@@ -677,8 +677,14 @@ def startup(config_dir):
677
677
help = 'Use pdb / breakpoint() instead of code.interact()' ,
678
678
default = False ,
679
679
)
680
+ @click .option (
681
+ '--use-pythonrc/--no-startup' ,
682
+ 'use_pythonrc' ,
683
+ help = 'Load the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.' ,
684
+ default = False ,
685
+ )
680
686
def command_shell (
681
- session_name , window_name , socket_name , socket_path , command , use_pdb
687
+ session_name , window_name , socket_name , socket_path , command , use_pdb , use_pythonrc
682
688
):
683
689
"""Launch python shell for tmux server, session, window and pane.
684
690
@@ -715,114 +721,13 @@ def command_shell(
715
721
else :
716
722
from .shell import launch
717
723
718
- launch (server = server , session = session , window = window , pane = pane )
719
-
720
-
721
- @cli .command (name = 'shell_plus' )
722
- @click .argument ('session_name' , nargs = 1 , required = False )
723
- @click .argument ('window_name' , nargs = 1 , required = False )
724
- @click .option ('-S' , 'socket_path' , help = 'pass-through for tmux -S' )
725
- @click .option ('-L' , 'socket_name' , help = 'pass-through for tmux -L' )
726
- @click .option (
727
- '-c' ,
728
- 'command' ,
729
- help = 'Instead of opening shell, execute python code in libtmux and exit' ,
730
- )
731
- @click .option (
732
- '--use-pythonrc/--no-startup' ,
733
- 'use_pythonrc' ,
734
- help = 'Load the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.' ,
735
- default = False ,
736
- )
737
- def command_shell_plus (
738
- session_name ,
739
- window_name ,
740
- socket_name ,
741
- socket_path ,
742
- command ,
743
- use_pythonrc ,
744
- ):
745
- """shell w/ tab completion.
746
-
747
- Credits: django-extensions shell_plus.py 51fef74 (MIT License)
748
- """
749
- server = Server (socket_name = socket_name , socket_path = socket_path )
750
-
751
- util .raise_if_tmux_not_running (server = server )
752
-
753
- current_pane = util .get_current_pane (server = server )
754
-
755
- session = util .get_session (
756
- server = server , session_name = session_name , current_pane = current_pane
757
- )
758
-
759
- window = util .get_window (
760
- session = session , window_name = window_name , current_pane = current_pane
761
- )
762
-
763
- pane = util .get_pane (window = window , current_pane = current_pane ) # NOQA: F841
764
-
765
- if command is not None :
766
- exec (command )
767
- else :
768
- # Using normal Python shell
769
- import code
770
-
771
- import libtmux
772
-
773
- imported_objects = {
774
- 'libtmux' : libtmux ,
775
- 'Server' : libtmux .Server ,
776
- 'Session' : libtmux .Session ,
777
- 'Window' : libtmux .Window ,
778
- 'Pane' : libtmux .Pane ,
779
- 'server' : server ,
780
- 'session' : session ,
781
- 'window' : window ,
782
- 'pane' : pane ,
783
- }
784
-
785
- try :
786
- # Try activating rlcompleter, because it's handy.
787
- import readline
788
- except ImportError :
789
- pass
790
- else :
791
- # We don't have to wrap the following import in a 'try', because
792
- # we already know 'readline' was imported successfully.
793
- import rlcompleter
794
-
795
- readline .set_completer (rlcompleter .Completer (imported_objects ).complete )
796
- # Enable tab completion on systems using libedit (e.g. macOS).
797
- # These lines are copied from Lib/site.py on Python 3.4.
798
- readline_doc = getattr (readline , '__doc__' , '' )
799
- if readline_doc is not None and 'libedit' in readline_doc :
800
- readline .parse_and_bind ("bind ^I rl_complete" )
801
- else :
802
- readline .parse_and_bind ("tab:complete" )
803
-
804
- # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
805
- # conventions and get $PYTHONSTARTUP first then .pythonrc.py.
806
- if use_pythonrc :
807
- for pythonrc in set (
808
- [os .environ .get ("PYTHONSTARTUP" ), os .path .expanduser ('~/.pythonrc.py' )]
809
- ):
810
- if not pythonrc :
811
- continue
812
- if not os .path .isfile (pythonrc ):
813
- continue
814
- with open (pythonrc ) as handle :
815
- pythonrc_code = handle .read ()
816
- # Match the behavior of the cpython shell where an error in
817
- # PYTHONSTARTUP prints an exception and continues.
818
- try :
819
- exec (compile (pythonrc_code , pythonrc , 'exec' ), imported_objects )
820
- except Exception :
821
- import traceback
822
-
823
- traceback .print_exc ()
824
-
825
- code .interact (local = imported_objects )
724
+ launch (
725
+ server = server ,
726
+ session = session ,
727
+ window = window ,
728
+ pane = pane ,
729
+ use_pythonrc = use_pythonrc ,
730
+ )
826
731
827
732
828
733
@cli .command (name = 'freeze' )
0 commit comments